-
Notifications
You must be signed in to change notification settings - Fork 6
Extend library API part 9 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request extends the RLib library API with new utility methods for string operations, enum alias resolution, and array sorting capabilities. The changes include version bumping from 10.0.alpha9 to 10.0.alpha10.
Changes:
- Added
AliasedEnuminterface andAliasedEnumMaputility for resolving enum constants by string aliases - Extended
StringUtilswith blank checking methods (isBlank,isNotBlank,ifBlank) complementing existing empty checking methods - Added sort functionality to
MutableArrayinterface with implementations for natural ordering and custom comparators - Bumped library version to 10.0.alpha10 in build configuration and README
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| rlib-common/src/main/java/javasabr/rlib/common/AliasedEnum.java | New interface for enums with string aliases |
| rlib-common/src/main/java/javasabr/rlib/common/util/AliasedEnumMap.java | New utility class to resolve enum constants by aliases with validation |
| rlib-common/src/test/java/javasabr/rlib/common/util/AliasedEnumMapTest.java | Test coverage for AliasedEnumMap functionality |
| rlib-common/src/main/java/javasabr/rlib/common/util/StringUtils.java | Added blank checking methods and updated documentation |
| rlib-common/src/test/java/javasabr/rlib/common/util/StringUtilsTest.java | Test coverage for new string utility methods |
| rlib-collections/src/main/java/javasabr/rlib/collections/array/MutableArray.java | Added sort method declarations to interface |
| rlib-collections/src/main/java/javasabr/rlib/collections/array/impl/AbstractMutableArray.java | Implemented sort methods with natural order and custom comparator support |
| rlib-collections/src/main/java/javasabr/rlib/collections/array/impl/CopyOnWriteMutableArray.java | Thread-safe sort implementation using copy-on-write strategy |
| rlib-collections/src/test/java/javasabr/rlib/collections/array/MutableArrayTest.java | Test coverage for array sorting functionality |
| build.gradle | Version bump to 10.0.alpha10 |
| README.md | Version reference update to 10.0.alpha10 |
| public class AliasedEnumMap<T extends Enum<T> & AliasedEnum<T>> { | ||
|
|
||
| Map<String, T> aliasToValue; | ||
|
|
||
| public AliasedEnumMap(Class<T> enumClass) { | ||
| var enumConstants = enumClass.getEnumConstants(); | ||
| var aliasToValue = new HashMap<String, T>(); | ||
|
|
||
| for (T enumConstant : enumConstants) { | ||
| for (String alias : enumConstant.aliases()) { | ||
| T previous = aliasToValue.put(alias, enumConstant); | ||
| if (previous != null) { | ||
| throw new IllegalArgumentException("Detect duplicated alias:[%s] for [%s] and [%s]".formatted( | ||
| alias, | ||
| previous.name(), | ||
| enumConstant.name())); | ||
| } | ||
| } | ||
| } | ||
| this.aliasToValue = Map.copyOf(aliasToValue); | ||
| } | ||
|
|
||
| @Nullable | ||
| public T resolve(String alias) { | ||
| return aliasToValue.get(alias); | ||
| } | ||
|
|
||
| public T resolve(String alias, T def) { | ||
| T resolved = resolve(alias); | ||
| return resolved == null ? def : resolved; | ||
| } | ||
|
|
||
| public T require(String alias) { | ||
| T constant = resolve(alias); | ||
| if (constant == null) { | ||
| throw new IllegalArgumentException("Unknown enum constant for alias:[%s]".formatted(alias)); | ||
| } | ||
| return constant; | ||
| } |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation for public API. This new class should have a class-level Javadoc comment explaining its purpose and usage, and each public method (constructor, resolve, require) should be documented with parameter descriptions, return value descriptions, and any exceptions that may be thrown (e.g., IllegalArgumentException for duplicate aliases in constructor, or for unknown aliases in require()).
rlib-collections/src/main/java/javasabr/rlib/collections/array/impl/AbstractMutableArray.java
Outdated
Show resolved
Hide resolved
rlib-common/src/main/java/javasabr/rlib/common/util/AliasedEnumMap.java
Outdated
Show resolved
Hide resolved
rlib-common/src/test/java/javasabr/rlib/common/util/AliasedEnumMapTest.java
Outdated
Show resolved
Hide resolved
rlib-collections/src/test/java/javasabr/rlib/collections/array/MutableArrayTest.java
Outdated
Show resolved
Hide resolved
|
|
||
| void sort(); | ||
|
|
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation for public API methods. The newly added sort methods should have Javadoc comments describing their behavior, parameters, and any exceptions they might throw. For example, the sort() method should document that it sorts elements in their natural order (if Comparable) or by hashcode, and that ConcurrentModificationException might be thrown in concurrent contexts.
| void sort(); | |
| /** | |
| * Sorts the elements of this array in-place. | |
| * <p> | |
| * If the elements implement {@link Comparable}, they are sorted according to their natural | |
| * order. Otherwise, elements are ordered by their {@link Object#hashCode()} values. | |
| * | |
| * @throws java.lang.ClassCastException if the elements are not mutually comparable when | |
| * natural ordering is used | |
| * @throws java.util.ConcurrentModificationException if the array is structurally modified | |
| * while the sort is in progress | |
| */ | |
| void sort(); | |
| /** | |
| * Sorts the elements of this array in-place using the provided comparator. | |
| * | |
| * @param comparator the comparator to determine the order of the elements; must not be | |
| * {@code null} | |
| * | |
| * @throws java.util.ConcurrentModificationException if the array is structurally modified | |
| * while the sort is in progress | |
| */ |
| mutableArray.addAll(Array.of("10", "99", "5", "3", "77", "45", "25", "56")); | ||
|
|
||
| // when: | ||
| mutableArray.sort(Comparator.comparingInt(Integer::parseInt)); |
Copilot
AI
Jan 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential uncaught 'java.lang.NumberFormatException'.
| mutableArray.sort(Comparator.comparingInt(Integer::parseInt)); | |
| mutableArray.sort(Comparator.comparingInt(value -> { | |
| try { | |
| return Integer.parseInt(value); | |
| } catch (NumberFormatException e) { | |
| throw new IllegalArgumentException("Non-numeric value in array: " + value, e); | |
| } | |
| })); |
Co-authored-by: Copilot <[email protected]>
…/impl/AbstractMutableArray.java Co-authored-by: Copilot <[email protected]>
…mMap.java Co-authored-by: Copilot <[email protected]>
…mMapTest.java Co-authored-by: Copilot <[email protected]>
…/MutableArrayTest.java Co-authored-by: Copilot <[email protected]>
|
|
|
|
|
|
Extend library API part 9