This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new 81c2c53f78 Utility class cleanup
81c2c53f78 is described below
commit 81c2c53f78d3ea086e90544b7c7392a3ed6e5b8c
Author: James Bognar <[email protected]>
AuthorDate: Mon Oct 27 13:10:10 2025 -0400
Utility class cleanup
---
TODO-completed.md | 54 +++
TODO-irsUtils.md | 505 ---------------------
TODO.md | 48 --
.../juneau/junit/bct/BasicBeanConverter.java | 5 +-
.../juneau/common/collections/SimpleMap.java | 6 +-
.../apache/juneau/common/io/FileReaderBuilder.java | 6 +-
.../apache/juneau/common/io/FileWriterBuilder.java | 6 +-
.../juneau/common/utils/AnnotationUtils.java | 8 +-
.../org/apache/juneau/common/utils/AsciiSet.java | 66 +--
.../org/apache/juneau/common/utils/ClassUtils.java | 4 +-
.../org/apache/juneau/common/utils/Console.java | 41 +-
.../juneau/common/utils/ResourceBundleUtils.java | 19 -
.../java/org/apache/juneau/common/utils/Utils.java | 49 +-
.../java/org/apache/juneau/BeanPropertyMeta.java | 24 +-
.../apache/juneau/annotation/AnnotationImpl.java | 4 +-
.../main/java/org/apache/juneau/cp/FileFinder.java | 14 +-
.../main/java/org/apache/juneau/cp/Messages.java | 24 +-
.../java/org/apache/juneau/rest/RestContext.java | 6 +-
.../apache/juneau/rest/staticfile/StaticFiles.java | 12 +-
19 files changed, 203 insertions(+), 698 deletions(-)
diff --git a/TODO-completed.md b/TODO-completed.md
index 5e0f00f3c3..1ed4946729 100644
--- a/TODO-completed.md
+++ b/TODO-completed.md
@@ -101,6 +101,60 @@ This file contains TODO items that have been completed and
moved from TODO.md.
- **Status**: COMPLETED
- **Details**: Added `isEmpty(CharSequence)` method that delegates to
`StringUtils.isEmpty(CharSequence)`, along with `isBlank(CharSequence)` and
`isNotEmpty(CharSequence)` overloads. Also added overloads for
`isEmpty(Collection)`, `isEmpty(Map)`, `isNotEmpty(Collection)`, and
`isNotEmpty(Map)`. All methods include comprehensive Javadocs.
+## Code Style and Consistency
+
+- **TODO-30** ✅ Ensure all Builder methods are consistently using "value" as
setter parameter names when it's a single parameter and it's obvious what
property is being set.
+ - **Status**: COMPLETED
+ - **Details**: Updated 13 single-parameter builder methods across 7 files to
use "value" as the parameter name:
+ - `FileReaderBuilder.file(File)`, `FileWriterBuilder.file(File)`,
`AsciiSet.Builder.chars(String)`
+ - `Messages.Builder.locale(Locale)`, `Messages.Builder.locale(String)`,
`Messages.Builder.name(String)`, `Messages.Builder.parent(Messages)`
+ - `FileFinder.Builder.path(Path)`,
`BeanPropertyMeta.Builder.beanRegistry(BeanRegistry)`,
`BeanPropertyMeta.Builder.delegateFor(BeanPropertyMeta)`,
`BeanPropertyMeta.Builder.overrideValue(Object)`
+ - `RestContext.Builder.config(Config)`,
`StaticFiles.Builder.mimeTypes(MimeTypeDetector)`,
`StaticFiles.Builder.path(Path)`
+ - **Note**: RestClient/MockRestClient builder methods with Apache HttpClient
technical parameters (proxy, sslContext, retryHandler, etc.) were intentionally
kept with descriptive names for clarity. User also updated additional methods
in `AsciiSet`, `FileFinder`, and `BeanPropertyMeta` for consistency.
+
+- **TODO-38** ✅ Find methods in com.sfdc.irs.Utils that don't exist in
org.apache.juneau.common.utils.Utils and come up with a plan to add ones that
make sense.
+ - **Status**: COMPLETED
+ - **Details**: Reviewed methods in `com.sfdc.irs.Utils` and determined that
all generally useful utility methods have already been added to
`org.apache.juneau.common.utils.Utils` or other appropriate `XUtils` classes.
Methods remaining in `com.sfdc.irs.Utils` are either specific to IRS
functionality or have equivalent implementations already available in Juneau's
utility classes.
+
+- **TODO-55** ✅ Replace multiple instances of assertArgNotNull with
assertArgsNotNull.
+ - **Status**: COMPLETED
+ - **Details**: Replaced 8 occurrences across 3 files:
+ - `BctAssertions.java`: 6 methods with consecutive calls (assertBean,
assertBeans, assertContains, assertContainsAll, assertList, assertMapped)
+ - `ClassUtils.java`: 1 method (getParameterType)
+ - `SimpleMap.java`: 1 constructor
+ All changes compile and all tests pass.
+
+- **TODO-56** ✅ Rename AnnotationUtils.hashCode to hash.
+ - **Status**: COMPLETED
+ - **Details**: Already completed before this task was added.
+
+- **TODO-57** ✅ Add method Utils.eq(Annotation, Annotation) that calls
AnnotationUtils.equals.
+ - **Status**: COMPLETED
+ - **Details**: Added an overload of `Utils.eq()` specifically for
annotations that delegates to `AnnotationUtils.equals()` to ensure proper
annotation comparison according to the annotation equality contract defined in
{@link java.lang.annotation.Annotation#equals(Object)}. Also added
corresponding `Utils.ne(Annotation, Annotation)` method for inequality checks.
+
+- **TODO-58** ✅ Update Utils.hash to use AnnotationUtils.hash() for
calculating hashes of annotations.
+ - **Status**: COMPLETED
+ - **Details**: Updated `Utils.hash()` to check if values are annotations and
use `AnnotationUtils.hash()` for them, maintaining the standard hash
calculation algorithm (31 * result + element hash) for consistency with
`Objects.hash()`.
+
+- **TODO-59** ✅ Move ClassUtils.cn and scn to Utils.
+ - **Status**: COMPLETED
+ - **Details**: Already completed before this task was added.
+
+- **TODO-61** ✅ Console.format seems to duplicate Utils.f. Let's remove it.
+ - **Status**: COMPLETED
+ - **Details**: Removed the `Console.format()` method which was duplicating
functionality already provided by `Utils.f()`. Updated `Console.err()` and
`Console.out()` to call `Utils.f()` directly instead. Also corrected outdated
javadocs that incorrectly claimed the class used Json5 marshalling when it
actually just called `toString()` on arguments - now properly documents the use
of `MessageFormat`.
+
+- **TODO-62** ✅ ResourceBundleUtils.empty() appears to be unused. Let's remove
it if so.
+ - **Status**: COMPLETED
+ - **Details**: Already completed before this task was added.
+
+- **TODO-63** ✅ Look for places in code where ThrowableUtils.illegalArg and
runtimeException can be used.
+ - **Status**: COMPLETED
+ - **Details**: Replaced 2 instances in `BasicBeanConverter.java`:
+ - Line 743: `new RuntimeException(f("Could not find extractor..."))` →
`runtimeException("Could not find extractor...")`
+ - Line 765: `new IllegalArgumentException(f("Object of type {0} could not
be converted to a list."))` → `illegalArg("Object of type {0} could not be
converted to a list.")`
+ Added static import for `ThrowableUtils` methods. These utility methods
provide cleaner syntax and consistent exception creation with formatted
messages.
+
## Notes
Items are marked as completed when:
diff --git a/TODO-irsUtils.md b/TODO-irsUtils.md
deleted file mode 100644
index 441236a502..0000000000
--- a/TODO-irsUtils.md
+++ /dev/null
@@ -1,505 +0,0 @@
-# TODO: com.sfdc.irs.Utils Methods to Copy to Juneau
-
-This file tracks methods from `com.sfdc.irs.Utils` that should be evaluated
for copying to Apache Juneau utility classes.
-
-## Methods Already in Juneau (No Action Needed)
-
-These methods already exist in Juneau utility classes:
-
-1. `eq(T s1, T s2)` - Exists in `Utils`
-2. `ne(T s1, T s2)` - Exists in `Utils`
-3. `isEmpty(String o)` - Exists in `StringUtils`
-4. `isNotEmpty(String o)` - Exists in `StringUtils`
-5. `split(String s)` - Wrapper to `StringUtils.split()`
-6. `split(String s, char delim)` - Wrapper to `StringUtils.split()`
-7. `json(Object o)` - Uses `Json5.DEFAULT.write()` (Juneau already has this)
-8. `abbreviate(String value, int length)` - Wrapper to
`StringUtils.abbreviate()`
-9. `isNumeric(String val)` - Wrapper to `StringUtils.isNumeric()`
-10. `emptyIfNull(String value)` - Exists in `StringUtils`
-11. `nullIfEmpty(String value)` - Exists in `StringUtils`
-12. `splitQcd(String s, ArrayList<String> result)` - Complex quoted CSV
parsing (likely already exists)
-13. `beanMap(T bean)` - Uses `BeanContext.DEFAULT_SESSION.toBeanMap()`
-14. `getBeanProp(Object o, String name)` - SFDC-specific bean property access
-15. `safe(ThrowingSupplier<T> s)` - Exists in Juneau as similar patterns
-16. `safe(ThrowingSupplier<T> s, ThrowableLogger logger)` - Exists in Juneau
as similar patterns
-17. `s(Object val)` - Exists as `StringUtils.stringify()` or similar
-18. `escapeChars(String val)` - Wrapper to `StringUtils.escapeChars()`
-19. `endsWith(String s, char...chars)` - Wrapper to `StringUtils.endsWith()`
-20. `indexOf(String s, char...chars)` - Wrapper to `StringUtils.indexOf()`
-21. `isNotNumeric(String s)` - Can be `!isNumeric(s)`
-22. `compare(Object o1, Object o2)` - May already exist
-23. `getStackTrace(Throwable t)` - May already exist in `ThrowableUtils`
-
-## Methods to Consider Copying
-
-### String Methods (Target: `StringUtils`)
-
-- [ ] **1. `lc(String s)`** - Lowercase with null safety
- ```java
- public static String lc(String s) {
- return s == null ? null : s.toLowerCase();
- }
- ```
-
-- [ ] **2. `uc(String s)`** - Uppercase with null safety
- ```java
- public static String uc(String s) {
- return s == null ? null : s.toUpperCase();
- }
- ```
-
-- [ ] **3. `eqic(Object a, Object b)`** - Equals ignore case (converts both to
strings)
- ```java
- public static boolean eqic(Object a, Object b) {
- if (a == null && b == null) { return true; }
- if (a == null || b == null) { return false; }
- return Objects.equals(a.toString().toLowerCase(),
b.toString().toLowerCase());
- }
- ```
-
-- [ ] **4. `articlized(String subject)`** - Adds 'a' or 'an' before word
- ```java
- public static String articlized(String subject) {
- var p = Pattern.compile("^[AEIOUaeiou].*");
- return (p.matcher(subject).matches() ? "an " : "a ") + subject;
- }
- ```
-
-- [ ] **5. `obfuscate(String s)`** - Returns obfuscated string (e.g.,
"p*******")
- ```java
- public static String obfuscate(String s) {
- if (s == null || s.length() < 2)
- return "*";
- return s.substring(0, 1) + s.substring(1).replaceAll(".", "*");
- }
- ```
-
-- [ ] **6. `coalesce(String...vals)`** - Returns first non-empty string
- ```java
- public static String coalesce(String...vals) {
- for (String v : vals) {
- if (isNotEmpty(v)) {
- return v;
- }
- }
- return null;
- }
- ```
-
-- [ ] **7. `splits(String s)`** - Splits comma-delimited list to Stream
- ```java
- public static Stream<String> splits(String s) {
- return Stream.of(isEmpty(s) ? new String[0] : split(s)).map(String::trim);
- }
- ```
-
-- [ ] **8. `splits(String s, char delim)`** - Splits delimited list to Stream
with custom delimiter
- ```java
- public static Stream<String> splits(String s, char delim) {
- return Stream.of(isEmpty(s) ? new String[0] : split(s,
delim)).map(String::trim);
- }
- ```
-
-- [ ] **9. `cdlToList(String s)`** - Comma-delimited string to List
- ```java
- public static List<String> cdlToList(String s) {
- return Stream.of(isEmpty(s) ? new String[0] :
split(s)).map(String::trim).collect(toList());
- }
- ```
-
-- [ ] **10. `join(String...values)`** - Combines values into comma-delimited
list
- ```java
- public static String join(String...values) {
- return StringUtils.join(values, ',');
- }
- ```
-
-- [ ] **11. `join(Collection<?> values)`** - Combines collection into
comma-delimited list
- ```java
- public static String join(Collection<?> values) {
- return StringUtils.joine(new ArrayList<>(values), ',');
- }
- ```
-
-- [ ] **12. `contains(String s, String...values)`** - Null-safe contains check
for multiple values
- ```java
- public static boolean contains(String s, String...values) {
- if (s == null || values == null || values.length == 0)
- return false;
- for (String v : values) {
- if (s.contains(v))
- return true;
- }
- return false;
- }
- ```
-
-- [ ] **13. `contains(String s, char...values)`** - Null-safe contains check
for multiple chars
- ```java
- public static boolean contains(String s, char...values) {
- if (s == null || values == null || values.length == 0)
- return false;
- for (char v : values) {
- if (s.indexOf(v) >= 0)
- return true;
- }
- return false;
- }
- ```
-
-- [ ] **14. `notContains(String s, String...values)`** - Null-safe
not-contains check
- ```java
- public static boolean notContains(String s, String...values) {
- return ! contains(s, values);
- }
- ```
-
-- [ ] **15. `notContains(String s, char...values)`** - Null-safe not-contains
check for chars
- ```java
- public static boolean notContains(String s, char...values) {
- return ! contains(s, values);
- }
- ```
-
-- [ ] **16. `stringify(Object o)`** - Enhanced stringify with
Collection/Map/Calendar support
- ```java
- public static String stringify(Object o) {
- if (o instanceof Collection)
- return (String)
Collection.class.cast(o).stream().map(Utils::stringify).collect(joining(",","[","]"));
- if (o instanceof Map)
- return (String)
Map.class.cast(o).entrySet().stream().map(Utils::stringify).collect(joining(",","{","}"));
- if (o instanceof Map.Entry) {
- var e = Map.Entry.class.cast(o);
- return stringify(e.getKey()) + '=' + stringify(e.getValue());
- }
- if (o instanceof GregorianCalendar) {
- return
GregorianCalendar.class.cast(o).toZonedDateTime().format(DateTimeFormatter.ISO_INSTANT);
- }
- if (o != null && o.getClass().isArray()) {
- List<Object> l = list();
- for (var i = 0; i < Array.getLength(o); i++) {
- l.add(Array.get(o, i));
- }
- return stringify(l);
- }
- return StringUtils.stringify(o);
- }
- ```
-
-### Utils Methods
-
-- [ ] **17. `b(Object val)`** - Converts string/object to boolean
- ```java
- public static boolean b(Object val) {
- return
ofNullable(val).map(Object::toString).map(Boolean::valueOf).orElse(false);
- }
- ```
-
-- [ ] **18. `isBetween(int n, int lower, int higher)`** - Check if number is
inclusively between two values
- ```java
- public static boolean isBetween(int n, int lower, int higher) {
- return n >= lower && n <= higher;
- }
- ```
-
-- [ ] **19. `parseInt(String value)`** - parseInt with underscore removal
- ```java
- public static int parseInt(String value) {
- return Integer.parseInt(removeUnderscores(value));
- }
- ```
-
-- [ ] **20. `parseLong(String value)`** - parseLong with underscore removal
- ```java
- public static long parseLong(String value) {
- return Long.parseLong(removeUnderscores(value));
- }
- ```
-
-- [ ] **21. `parseFloat(String value)`** - parseFloat with underscore removal
- ```java
- public static float parseFloat(String value) {
- return Float.parseFloat(removeUnderscores(value));
- }
- ```
-
-- [ ] **22. `optional(T value)`** - Optional.ofNullable but treats -1 as null
- ```java
- public static <T extends Number> Optional<T> optional(T value) {
- return Optional.ofNullable(value).filter(x -> x.intValue() >= 0);
- }
- ```
-
-- [ ] **23. `format(String pattern, Object...args)`** - MessageFormat.format
wrapper
- ```java
- public static String format(String pattern, Object...args) {
- if (notContains(pattern, "{"))
- return pattern;
- return MessageFormat.format(pattern, args);
- }
- ```
-
-- [ ] **24. `coalesce(T...vals)`** - Returns first non-null object
- ```java
- public static <T> T coalesce(T...vals) {
- for (T v : vals) {
- if (v != null) {
- return v;
- }
- }
- return null;
- }
- ```
-
-- [ ] **25. `eq(T o1, U o2, BiPredicate<T,U> test)`** - Equals with custom test
- ```java
- public static <T,U> boolean eq(T o1, U o2, BiPredicate<T,U> test) {
- if (o1 == null) { return o2 == null; }
- if (o2 == null) { return false; }
- if (o1 == o2) { return true; }
- return test.test(o1, o2);
- }
- ```
-
-### ThrowableUtils Methods
-
-- [ ] **26. `findCause(Throwable e, Class<T> cause)`** - Find exception in
cause chain
- ```java
- public static <T extends Throwable> Optional<T> findCause(Throwable e,
Class<T> cause) {
- while (e != null) {
- if (cause.isInstance(e)) { return Optional.of(cause.cast(e)); }
- e = e.getCause();
- }
- return Optional.empty();
- }
- ```
-
-- [ ] **27. `hash(Throwable t, String stopClass)`** - Calculate hash from
throwable stacktrace
- ```java
- public static int hash(Throwable t, String stopClass) {
- var i = 0;
- while (t != null) {
- for (StackTraceElement e : t.getStackTrace()) {
- if (e.getClassName().equals(stopClass))
- break;
- if (notContains(e.getClassName(), '$'))
- i = 31*i+e.hashCode();
- }
- t = t.getCause();
- }
- return i;
- }
- ```
-
-- [ ] **28. `runtimeException(String msg, Object...args)`** - Supplier for
RuntimeException
- ```java
- public static Supplier<RuntimeException> runtimeException(String msg,
Object...args) {
- return () -> new RuntimeException(MessageFormat.format(msg, args));
- }
- ```
-
-### CollectionUtils Methods
-
-- [ ] **29. `cdlToSet(String s)`** - Comma-delimited string to LinkedHashSet
- ```java
- public static LinkedHashSet<String> cdlToSet(String s) {
- return Stream.of(isEmpty(s) ? new String[0] :
split(s)).map(String::trim).collect(toCollection(LinkedHashSet::new));
- }
- ```
-
-- [ ] **30. `treeSet(Set<T> copyFrom)`** - Create TreeSet from Set
- ```java
- public static <T> TreeSet<T> treeSet(Set<T> copyFrom) {
- return copyFrom == null ? null : new TreeSet<>(copyFrom);
- }
- ```
-
-- [ ] **31. `treeSet(T...values)`** - Create TreeSet from varargs
- ```java
- public static <T> TreeSet<T> treeSet(T...values) {
- return new TreeSet<>(Arrays.asList(values));
- }
- ```
-
-- [ ] **32. `list(T...values)`** - Create ArrayList from varargs
- ```java
- public static <T> ArrayList<T> list(T...values) {
- return new ArrayList<>(Arrays.asList(values));
- }
- ```
-
-- [ ] **33. `set(T...values)`** - Create LinkedHashSet from varargs
- ```java
- public static <T> LinkedHashSet<T> set(T...values) {
- return new LinkedHashSet<>(Arrays.asList(values));
- }
- ```
-
-- [ ] **34. `appendSet(Set<T> existing, T...values)`** - Append values to set
(creates if null)
- ```java
- public static <T> Set<T> appendSet(Set<T> existing, T...values) {
- var existing2 = ofNullable(existing).orElse(new LinkedHashSet<>());
- Arrays.stream(values).forEach(existing2::add);
- return existing2;
- }
- ```
-
-- [ ] **35. `append(Set<E> set, E...values)`** - Append values to set
- ```java
- public static <E> Set<E> append(Set<E> set, E...values) {
- return set == null ? set(values) : addAll(set, values);
- }
- ```
-
-- [ ] **36. `addAll(C collection, E...elements)`** - Add all elements to
collection
- ```java
- public static <E, C extends Collection<E>> C addAll(C collection,
E...elements) {
- Collections.addAll(collection, elements);
- return collection;
- }
- ```
-
-- [ ] **37. `toTreeSet(Comparator<T> comparator)`** - Stream collector for
TreeSet
- ```java
- public static <T> Collector<T,?,TreeSet<T>> toTreeSet(Comparator<T>
comparator) {
- return Collectors.toCollection(() -> new TreeSet<>(comparator));
- }
- ```
-
-- [ ] **38. `map(Object...values)`** - Create LinkedHashMap from key/value
pairs
- ```java
- public static <K,V> LinkedHashMap<K,V> map(Object...values) {
- var m = new LinkedHashMap<K,V>();
- for (var i = 0; i < values.length; i+=2) {
- m.put((K)values[i], (V)values[i+1]);
- }
- return m;
- }
- ```
-
-- [ ] **39. `jmap(Object...values)`** - Create JsonMap from key/value pairs
- ```java
- public static JsonMap jmap(Object...values) {
- var m = new JsonMap();
- for (var i = 0; i < values.length; i+=2) {
- m.put(stringify(values[i]), values[i+1]);
- }
- return m;
- }
- ```
-
-- [ ] **40. `smap(Object...values)`** - Create string map from key/value pairs
- ```java
- public static Map<String,String> smap(Object...values) {
- var m = new LinkedHashMap<String,String>();
- for (var i = 0; i < values.length; i += 2) {
- m.put(stringify(values[i]), stringify(values[i + 1]));
- }
- return m;
- }
- ```
-
-- [ ] **41. `jlist(Object...values)`** - Create JsonList from values
- ```java
- public static JsonList jlist(Object...values) {
- return new JsonList(values);
- }
- ```
-
-### AssertionUtils Methods
-
-- [ ] **42. `assertOneOf(T actual, T...expected)`** - Assert value is one of
expected
- ```java
- public static final <T> T assertOneOf(T actual, T...expected) {
- for (T e : expected) {
- if (eq(actual,e)) return actual;
- }
- throw new AssertionError("Invalid value specified: " + actual);
- }
- ```
-
-### DateUtils Methods
-
-- [ ] **43. `calendar(String isoDateOrDuration)`** - Create Calendar from ISO
date/duration/year/short format
- ```java
- public static Calendar calendar(String isoDateOrDuration) throws
IllegalArgumentException {
- try {
- var x = isoDateOrDuration.charAt(0);
- if (x == 'P' || x == '-') {
- var c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- var duration = Duration.parse(isoDateOrDuration).toMillis() / 1000;
- c.add(Calendar.SECOND, (int)duration);
- return c;
- }
- if (notContains(isoDateOrDuration, '-')) {
- if (isoDateOrDuration.length() == 4) isoDateOrDuration += "0101";
- Calendar c = new GregorianCalendar(TimeZone.getTimeZone("Z"));
- c.setTime(SIMPLIFIED_DATE.get().parse(isoDateOrDuration));
- return c;
- }
- if (notContains(isoDateOrDuration, 'T')) {
- isoDateOrDuration += "T00:00:00Z";
- }
- var zdt = ZonedDateTime.ofInstant(Instant.parse(isoDateOrDuration),
ZoneId.of("Z"));
- return GregorianCalendar.from(zdt);
- } catch (DateTimeParseException | ParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
- ```
-
-- [ ] **44. `addSubtractDays(Calendar c, int days)`** - Add/subtract days from
Calendar
- ```java
- public static Calendar addSubtractDays(Calendar c, int days) {
- return ofNullable(c)
- .map(x -> (Calendar)x.clone())
- .map(x -> add(x, Calendar.DATE, days))
- .orElse(null);
- }
- ```
-
-- [ ] **45. `add(Calendar c, int field, int amount)`** - Add to calendar field
- ```java
- public static Calendar add(Calendar c, int field, int amount) {
- c.add(field, amount);
- return c;
- }
- ```
-
-- [ ] **46. `toZonedDateTime(Calendar c)`** - Convert Calendar to ZonedDateTime
- ```java
- public static Optional<ZonedDateTime> toZonedDateTime(Calendar c) {
- return
ofNullable(c).map(GregorianCalendar.class::cast).map(GregorianCalendar::toZonedDateTime);
- }
- ```
-
-### Utility Methods (May Not Be Needed)
-
-- [ ] **47. `stringSupplier(Supplier<?> s)`** - Convert Supplier to
Supplier<String>
- ```java
- public static Supplier<String> stringSupplier(Supplier<?> s) {
- return () -> Utils.stringify(s.get());
- }
- ```
- *Note: This seems very specific to logging - may not be generally useful.*
-
-## Summary
-
-- **Total Methods in com.sfdc.irs.Utils**: ~47 unique methods
-- **Methods Already in Juneau**: ~23 (wrappers or equivalents exist)
-- **Methods to Evaluate**: ~47 (some overlap, some new)
-- **Primary Targets**:
- - StringUtils: 16 methods
- - Utils: 9 methods
- - CollectionUtils: 13 methods
- - ThrowableUtils: 3 methods
- - AssertionUtils: 1 method
- - DateUtils: 4 methods
-
-## Next Steps
-
-1. Review each method and decide if it should be copied
-2. For approved methods, copy to appropriate utility class
-3. Add comprehensive unit tests
-4. Update TODO-38 in TODO.md when complete
-
diff --git a/TODO.md b/TODO.md
index 1ea9bb6637..f315b66572 100644
--- a/TODO.md
+++ b/TODO.md
@@ -15,40 +15,6 @@ This file tracks pending tasks for the Apache Juneau
project. For completed item
- [ ] TODO-15 It appears StringUtils is going to become a commonly-used
external class. Let's see if we can enhance it with commonly used string
utility methods.
- [ ] TODO-27 Determine if there are any other good candidates for
Stringifiers and Listifiers.
- [ ] TODO-29 Finish setting up SonarQube analysis in git workflow.
-- [x] TODO-37 Find and replace all instances of "x != null" with "nn(x)".
**COMPLETE** - Replaced approximately 1965+ instances of `!= null` with `nn()`
across production code in juneau-core, juneau-rest, juneau-bean, and
juneau-microservice modules (~98.6% reduction from initial ~1992). Includes:
- - Simple variable checks: 120+ variable names covering common patterns
- - Multi-variable expressions: `type != null && onClass != null`,
`beanContext != null && beanContext.cmCache != null`, etc.
- - Field access patterns: `e.value != null`, `meta.dynaProperty != null`,
`builder.xxx != null`, `p.xxx != null`, `n.uri != null`, etc.
- - Method call patterns: 30+ getter methods (`getDescription()`, `getUrl()`,
`getTags()`, `getName()`, `getVersion()`, etc.)
- - Ternary expressions: `value != null ? ...`, `builder != null ? ...`, `c !=
null ? c.getName() : ...`, etc.
- - Array elements: `store[c] != null`, `vars[i] != null`, etc.
- - Return statements: `return value != null`, `return o != null`, `return
nn(getPackage())`, etc.
- - Compound expressions: `&& authority != null`, `|| field != null`, `while
(pc != null &&`, etc.
- - Boolean methods: `isAbstract()`, `isInterface()`, `isPrimitive()`, etc.
all converted to use `nn(c)`
- - Lambda expressions: `x -> m.get(x.inner()) != null` → `x ->
nn(m.get(x.inner()))`
- - Builder patterns: `.addIf(variable != null, ...)` → `.addIf(nn(variable),
...)` for 80+ common fields across OpenAPI/Swagger beans (including all
remaining addIf patterns: anyOf, authorizationCode, authorizationUrl, basePath,
callbacks, clientCredentials, definitions, host, implicit, in, info, mapping,
not, nullable, oneOf, password, paths, propertyName, refreshUrl, requestBody,
requiredProperties, requirements, scopes, securityDefinitions, servers,
swagger, tokenUrl, writeOnly)
- - Conservative ternary replacements: simple safe patterns only (including
path, partParser, schema, getName, getSimpleName patterns)
- - Method call chains: `cm.getSwap(this) != null`,
`beanFilter.getBeanDictionary() != null`, etc.
- - Variable assignments: `var isResolving = varResolver != null`, `boolean
isLoaded = content != null`, etc.
- - While loops: `while (e != null)`, `while (c != null)`, `while (type !=
null && ...)`, `} while (t != null && ...)`, `while ((key =
watchService.take()) != null)`, etc.
- - Else if patterns: 10+ else-if compound expressions
- - Field assignments: `this.def = mergedFormData != null &&`, `this.def =
mergedHeader != null &&`, etc.
- - Additional compound expressions: 100+ patterns with logical operators (&&,
||)
- - Boolean variable assignments: `boolean encodeEn = elementName != null`,
`boolean cr = o != null && ...`, `descriptionAdded |= description != null`, etc.
- - Complex multi-condition patterns: including validation checks, filters,
type checks, getter chains, annotation checks, etc.
- - OpenAPI/Swagger getter patterns: `pathItem.getDelete() != null`,
`pathItem.getGet() != null`, etc. (all HTTP methods)
- - Type checking patterns: `v != null && !
valueType.getInnerClass().isInstance(v)`, `arg != null &&
pt.isParentOf(arg.getClass())`, etc.
- - Stream filter lambdas: `filter(x -> x != null && ...)` → `filter(x ->
nn(x) && ...)`
- - Complex nested ternaries: `nn(ed) && nn(ed.getDescription()) ?
ed.getDescription() : (ed != null ? ed.getUrl() : null)` → `... (nn(ed) ?
ed.getUrl() : null)`
- - Annotation chains: `m.getAnnotation(Deprecated.class) != null ||
m.getDeclaringClass().getAnnotation(Deprecated.class) != null` → `nn(...) ||
nn(...)`
- - Constructor/method reflection patterns: `c.getPublicConstructor(...) !=
null` → `nn(c.getPublicConstructor(...))`
- All changes compile and install successfully with all tests passing. **Only
27 instances remain (down from initial ~1992)**, all intentionally preserved:
- - 1 in `Utils.isNotNull()` method definition (must remain as-is)
- - 7 in `AssertionPredicates` lambda test predicates (preserved for clarity
in test expressions)
- - 17 in `AssertionUtils` with `assertArg` statements (preserved for clarity
in argument validation)
- - 2 in `PartList` and `HeaderList` with `assertArg` statements (preserved
for clarity)
- **Special care taken to preserve Utils.isNotNull() method definition by
excluding Utils.java from all replacements.**
-- [ ] TODO-38 Find methods in com.sfdc.irs.Utils that don't exist in
org.apache.juneau.common.utils.Utils and come up with a plan to add ones that
make sense (e.g. they're not tied to other code in com.sfdc.irs and they don't
already have equivalents in other XUtils classes).
- [ ] TODO-39 Use static imports for all method calls to AnnotationUtils.
- [ ] TODO-40 Use static imports for all method calls to ArrayUtils.
- [ ] TODO-41 Use static imports for all method calls to AssertionUtils.
@@ -65,17 +31,7 @@ This file tracks pending tasks for the Apache Juneau
project. For completed item
- [ ] TODO-52 Use static imports for all method calls to Utils.
- [ ] TODO-53 Use static imports for all method calls to BctUtils.
- [ ] TODO-54 Search for places in code where Calendar should be replaced with
ZonedDateTime.
-- [ ] TODO-55 Replace multiple instances of assertArgNotNull with
assertArgsNotNull.
-- [ ] TODO-56 Rename AnnotationUtils.hashCode to hash.
-- [ ] TODO-57 Add method Utils.eq(Annotation, Annotation) that calls
AnnotationUtils.equals.
-- [ ] TODO-58 Update Utils.hash to use AnnotationUtils.hash() for calculating
hashes of annotations.
-- [ ] TODO-59 Move ClassUtils.cn and scn to Utils.
- [ ] TODO-60 There seems to be duplication in ArrayUtils and CollectionUtils.
Let's merge ArrayUtils into CollectionUtils.
-- [ ] TODO-61 Console.format seems to duplicate Utils.f. Let's remove it.
-- [ ] TODO-62 ResourceBundleUtils.empty() appears to be unused. Let's remove
it if so.
-- [ ] TODO-63 Look for places in code where ThrowableUtils.illegalArg and
runtimeException can be used.
-- [x] TODO-64 Add a Utils.nn(Object...) that validates that all parameters are
not null. **COMPLETE** - Added varargs `nn(Object...)` method that returns true
if all parameters are not null. Method includes comprehensive Javadoc with
examples. Search of codebase found no existing patterns of `nn(x) && nn(y)`
chains to consolidate, likely because TODO-37's systematic replacements
converted compound null checks individually.
-- [x] TODO-65 Add Utils.isEmpty(CharSequence) which redirects to
StringUtils.isEmpty(CharSequence). **COMPLETE** - Added `isEmpty(CharSequence)`
method that delegates to `StringUtils.isEmpty(CharSequence)`, along with
`isBlank(CharSequence)` and `isNotEmpty(CharSequence)` overloads. Also added
overloads for `isEmpty(Collection)`, `isEmpty(Map)`, `isNotEmpty(Collection)`,
and `isNotEmpty(Map)`. All methods include comprehensive Javadocs.
## Framework Improvements
@@ -98,7 +54,3 @@ This TODO list tracks specific issues that need to be
addressed in the Juneau pr
## Website/Docs
- [ ] TODO-29 Add searching to website using Algolia DocSearch.
-
-## Code Style and Consistency
-
-- [ ] TODO-30 Ensure all Builder methods are consistently using "value" as
setter parameter names when it's a single parameter and it's obvious what
property is being set.
diff --git
a/juneau-core/juneau-bct/src/main/java/org/apache/juneau/junit/bct/BasicBeanConverter.java
b/juneau-core/juneau-bct/src/main/java/org/apache/juneau/junit/bct/BasicBeanConverter.java
index d9f639e5de..af2c4a2356 100644
---
a/juneau-core/juneau-bct/src/main/java/org/apache/juneau/junit/bct/BasicBeanConverter.java
+++
b/juneau-core/juneau-bct/src/main/java/org/apache/juneau/junit/bct/BasicBeanConverter.java
@@ -19,6 +19,7 @@ package org.apache.juneau.junit.bct;
import static java.util.Optional.*;
import static java.util.stream.Collectors.*;
import static org.apache.juneau.common.utils.AssertionUtils.*;
+import static org.apache.juneau.common.utils.ThrowableUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import java.io.*;
@@ -740,7 +741,7 @@ public class BasicBeanConverter implements BeanConverter {
public Object getProperty(Object object, String name) {
var o = swap(object);
return propertyExtractors.stream().filter(x ->
x.canExtract(this, o, name)).findFirst()
- .orElseThrow(() -> new RuntimeException(f("Could not
find extractor for object of type {0}", o.getClass().getName()))).extract(this,
o, name);
+ .orElseThrow(() -> runtimeException("Could not find
extractor for object of type {0}", o.getClass().getName())).extract(this, o,
name);
}
@Override
@@ -761,7 +762,7 @@ public class BasicBeanConverter implements BeanConverter {
return arrayToList(o);
var o2 = o;
return listifierMap.computeIfAbsent(c,
this::findListifier).map(x -> (Listifier)x).map(x ->
(List<Object>)x.apply(this, o2))
- .orElseThrow(() -> new
IllegalArgumentException(f("Object of type {0} could not be converted to a
list.", scn(o2))));
+ .orElseThrow(() -> illegalArg("Object of type {0} could
not be converted to a list.", scn(o2)));
}
@Override
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/SimpleMap.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/SimpleMap.java
index c537f4a7f7..4e071cfa3c 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/SimpleMap.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/SimpleMap.java
@@ -16,6 +16,7 @@
*/
package org.apache.juneau.common.collections;
+import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import java.lang.reflect.*;
@@ -184,9 +185,8 @@ public class SimpleMap<K,V> extends AbstractMap<K,V> {
*/
@SuppressWarnings("unchecked")
public SimpleMap(K[] keys, V[] values) {
- AssertionUtils.assertArgNotNull("keys", keys);
- AssertionUtils.assertArgNotNull("values", values);
- AssertionUtils.assertArg(keys.length == values.length, "keys
''{0}'' and values ''{1}'' array lengths differ", keys.length, values.length);
+ assertArgsNotNull("keys", keys, "values", values);
+ assertArg(keys.length == values.length, "keys ''{0}'' and
values ''{1}'' array lengths differ", keys.length, values.length);
this.keys = keys;
this.values = values;
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileReaderBuilder.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileReaderBuilder.java
index cfdff427c9..6f6fb2a8c0 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileReaderBuilder.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileReaderBuilder.java
@@ -101,11 +101,11 @@ public class FileReaderBuilder {
/**
* Sets the file being written from.
*
- * @param file The file being written from.
+ * @param value The file being written from.
* @return This object.
*/
- public FileReaderBuilder file(File file) {
- this.file = file;
+ public FileReaderBuilder file(File value) {
+ this.file = value;
return this;
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileWriterBuilder.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileWriterBuilder.java
index fd6bc66375..c0302d1e67 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileWriterBuilder.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/io/FileWriterBuilder.java
@@ -121,11 +121,11 @@ public class FileWriterBuilder {
/**
* Sets the file being written to.
*
- * @param file The file being written to.
+ * @param value The file being written to.
* @return This object.
*/
- public FileWriterBuilder file(File file) {
- this.file = file;
+ public FileWriterBuilder file(File value) {
+ this.file = value;
return this;
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AnnotationUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AnnotationUtils.java
index 8391288b06..e288a5d3f6 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AnnotationUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AnnotationUtils.java
@@ -65,7 +65,7 @@ public class AnnotationUtils {
* @throws RuntimeException if an {@code Exception} is encountered
during annotation member access
* @throws IllegalStateException if an annotation method invocation
returns {@code null}
*/
- public static int hashCode(Annotation a) {
+ public static int hash(Annotation a) {
return getAnnotationMethods(a.annotationType()).mapToInt(x ->
hashMember(x.getName(), safeSupplier(() -> x.invoke(a)))).sum();
}
@@ -73,7 +73,7 @@ public class AnnotationUtils {
if (a1.length != a2.length)
return false;
for (int i = 0; i < a1.length; i++)
- if (! equals(a1[i], a2[i]))
+ if (ne(a1[i], a2[i]))
return false;
return true;
}
@@ -131,7 +131,7 @@ public class AnnotationUtils {
if (isArray(value))
return part1 ^
arrayMemberHash(value.getClass().getComponentType(), value);
if (value instanceof Annotation)
- return part1 ^ hashCode((Annotation)value);
+ return part1 ^ hash((Annotation)value);
return part1 ^ value.hashCode();
}
@@ -143,7 +143,7 @@ public class AnnotationUtils {
if (type.isArray())
return arrayMemberEquals(type.getComponentType(), o1,
o2);
if (type.isAnnotation())
- return equals((Annotation)o1, (Annotation)o2);
+ return eq((Annotation)o1, (Annotation)o2);
return o1.equals(o2);
}
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AsciiSet.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AsciiSet.java
index 436a63442c..1487e0ef2d 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AsciiSet.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/AsciiSet.java
@@ -40,25 +40,25 @@ public class AsciiSet {
/**
* Adds a set of characters to this set.
*
- * @param chars The characters to keep in this store.
+ * @param value The characters to keep in this store.
* @return This object.
*/
- public Builder chars(char...chars) {
- for (var i = 0; i < chars.length; i++)
- if (chars[i] < 128)
- store[chars[i]] = true;
+ public Builder chars(char...value) {
+ for (var i = 0; i < value.length; i++)
+ if (value[i] < 128)
+ store[value[i]] = true;
return this;
}
/**
* Adds a set of characters to this set.
*
- * @param chars The characters to keep in this store.
+ * @param value The characters to keep in this store.
* @return This object.
*/
- public AsciiSet.Builder chars(String chars) {
- for (var i = 0; i < chars.length(); i++) {
- var c = chars.charAt(i);
+ public AsciiSet.Builder chars(String value) {
+ for (var i = 0; i < value.length(); i++) {
+ var c = value.charAt(i);
if (c < 128)
store[c] = true;
}
@@ -82,11 +82,11 @@ public class AsciiSet {
/**
* Shortcut for calling multiple ranges.
*
- * @param s Strings of the form "A-Z" where A and Z represent
the first and last characters in the range.
+ * @param value Strings of the form "A-Z" where A and Z
represent the first and last characters in the range.
* @return This object.
*/
- public AsciiSet.Builder ranges(String...s) {
- for (var ss : s) {
+ public AsciiSet.Builder ranges(String...value) {
+ for (var ss : value) {
if (ss.length() != 3 || ss.charAt(1) != '-')
throw new
IllegalArgumentException("Value passed to ranges() must be 3 characters");
range(ss.charAt(0), ss.charAt(2));
@@ -107,11 +107,11 @@ public class AsciiSet {
/**
* Creates an ASCII set with the specified characters.
*
- * @param chars The characters to keep in this store.
+ * @param value The characters to keep in this store.
* @return A new object.
*/
- public static AsciiSet of(String chars) {
- return new Builder().chars(chars).build();
+ public static AsciiSet of(String value) {
+ return new Builder().chars(value).build();
}
private final boolean[] store;
@@ -123,26 +123,26 @@ public class AsciiSet {
/**
* Returns <jk>true</jk> if the specified character is in this store.
*
- * @param c The character to check.
+ * @param value The character to check.
* @return <jk>true</jk> if the specified character is in this store.
*/
- public boolean contains(char c) {
- if (c > 127)
+ public boolean contains(char value) {
+ if (value > 127)
return false;
- return store[c];
+ return store[value];
}
/**
* Returns <jk>true</jk> if the specified string contains at least one
character in this set.
*
- * @param s The string to test.
+ * @param value The string to test.
* @return <jk>true</jk> if the string is not null and contains at
least one character in this set.
*/
- public boolean contains(CharSequence s) {
- if (s == null)
+ public boolean contains(CharSequence value) {
+ if (value == null)
return false;
- for (var i = 0; i < s.length(); i++)
- if (contains(s.charAt(i)))
+ for (var i = 0; i < value.length(); i++)
+ if (contains(value.charAt(i)))
return true;
return false;
}
@@ -150,29 +150,29 @@ public class AsciiSet {
/**
* Returns <jk>true</jk> if the specified character is in this store.
*
- * @param c The character to check.
+ * @param value The character to check.
* @return <jk>true</jk> if the specified character is in this store.
*/
- public boolean contains(int c) {
- if (c < 0 || c > 127)
+ public boolean contains(int value) {
+ if (value < 0 || value > 127)
return false;
- return store[c];
+ return store[value];
}
/**
* Returns <jk>true</jk> if the specified string contains only
characters in this set.
*
- * @param s The string to test.
+ * @param value The string to test.
* @return
* <jk>true</jk> if the string contains only characters in this
set.
* <br>Nulls always return <jk>false</jk>.
* <br>Blanks always return <jk>true</jk>.
*/
- public boolean containsOnly(String s) {
- if (s == null)
+ public boolean containsOnly(String value) {
+ if (value == null)
return false;
- for (var i = 0; i < s.length(); i++)
- if (! contains(s.charAt(i)))
+ for (var i = 0; i < value.length(); i++)
+ if (! contains(value.charAt(i)))
return false;
return true;
}
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
index 3129372386..901d0f9f65 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
@@ -16,6 +16,7 @@
*/
package org.apache.juneau.common.utils;
+import static org.apache.juneau.common.utils.AssertionUtils.*;
import static org.apache.juneau.common.utils.Utils.*;
import java.lang.reflect.*;
@@ -113,8 +114,7 @@ public class ClassUtils {
* @throws IllegalArgumentException If the class is not a subclass of
the parameterized type or if the index is invalid.
*/
public static Class<?> getParameterType(Class<?> c, int index, Class<?>
pt) {
- AssertionUtils.assertArgNotNull("pt", pt);
- AssertionUtils.assertArgNotNull("c", c);
+ assertArgsNotNull("pt", pt, "c", c);
// We need to make up a mapping of type names.
Map<Type,Type> typeMap = new HashMap<>();
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Console.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Console.java
index 16807999cf..4da35c0ca9 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Console.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Console.java
@@ -22,8 +22,9 @@ import java.text.*;
/**
* A utility for logging formatted messages to the console.
- * Uses the {@link Json5} marshaller for serializing objects so any
- * POJOs can be used as format arguments.
+ *
+ * <p>
+ * Uses {@link java.text.MessageFormat} for formatting messages with arguments.
*/
public class Console {
@@ -31,7 +32,7 @@ public class Console {
* Prints a message with arguments to {@link System#err}.
*
* <p>
- * Arguments are automatically converted to strings using the {@link
Json5} marshaller.
+ * Arguments are formatted using {@link java.text.MessageFormat}.
*
* <p>
* Useful for debug messages.
@@ -42,41 +43,17 @@ public class Console {
* </p>
*
* @param msg The {@link MessageFormat}-styled message.
- * @param args The arguments sent to the the formatter after running
them through the {@link Json5} marshaller.
+ * @param args The arguments sent to the formatter.
*/
public static final void err(String msg, Object...args) {
- System.err.println(format(msg, args)); // NOT DEBUG
- }
-
- /**
- * Formats a message with arguments.
- *
- * <p>
- * Arguments are automatically converted to strings using the {@link
Json5} marshaller.
- *
- * <p>
- * Useful for debug messages.
- *
- * <h5 class='figure'>Example:</h5>
- * <p class='bjava'>
- * String <jv>msg</jv> =
Console.<jsm>format</jsm>(<js>"myPojo={0}"</js>, <jv>myPojo</jv>);
- * </p>
- *
- * @param msg The {@link MessageFormat}-styled message.
- * @param args The arguments sent to the the formatter after running
them through the {@link Json5} marshaller.
- * @return This object.
- */
- public static final String format(String msg, Object...args) {
- for (int i = 0; i < args.length; i++)
- args[i] = s(args[i]);
- return MessageFormat.format(msg, args);
+ System.err.println(f(msg, args)); // NOT DEBUG
}
/**
* Prints a message with arguments to {@link System#out}.
*
* <p>
- * Arguments are automatically converted to strings using the {@link
Json5} marshaller.
+ * Arguments are formatted using {@link java.text.MessageFormat}.
*
* <p>
* Useful for debug messages.
@@ -87,9 +64,9 @@ public class Console {
* </p>
*
* @param msg The {@link MessageFormat}-styled message.
- * @param args The arguments sent to the the formatter after running
them through the {@link Json5} marshaller.
+ * @param args The arguments sent to the formatter.
*/
public static final void out(String msg, Object...args) {
- System.out.println(format(msg, args));
+ System.out.println(f(msg, args));
}
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ResourceBundleUtils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ResourceBundleUtils.java
index 262f0327cf..69b330de4f 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ResourceBundleUtils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ResourceBundleUtils.java
@@ -27,25 +27,6 @@ import java.util.*;
*/
public class ResourceBundleUtils {
- private static final ResourceBundle EMPTY = new ResourceBundle() {
- @Override
- public Enumeration<String> getKeys() { return
Collections.emptyEnumeration(); }
-
- @Override
- protected Object handleGetObject(String key) {
- return null;
- }
- };
-
- /**
- * Returns an empty resource bundle.
- *
- * @return An empty resource bundle.
- */
- public static ResourceBundle empty() {
- return EMPTY;
- }
-
/**
* Same as {@link ResourceBundle#getBundle(String, Locale,
ClassLoader)} but never throws a {@link MissingResourceException}.
*
diff --git
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
index dafaced1a7..7765dc6651 100644
---
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
+++
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/Utils.java
@@ -386,6 +386,39 @@ public class Utils {
return test.test(o1, o2);
}
+ /**
+ * Tests two annotations for equality using the criteria presented in
the {@link java.lang.annotation.Annotation#equals(Object)} API docs.
+ *
+ * <p>
+ * This method delegates to {@link
AnnotationUtils#equals(java.lang.annotation.Annotation,
java.lang.annotation.Annotation)}
+ * to ensure proper annotation comparison according to the annotation
equality contract.
+ *
+ * @param a1 Annotation 1.
+ * @param a2 Annotation 2.
+ * @return <jk>true</jk> if the two annotations are equal or both are
<jk>null</jk>.
+ * @see AnnotationUtils#equals(java.lang.annotation.Annotation,
java.lang.annotation.Annotation)
+ */
+ public static boolean eq(java.lang.annotation.Annotation a1,
java.lang.annotation.Annotation a2) {
+ return AnnotationUtils.equals(a1, a2);
+ }
+
+ /**
+ * Tests two annotations for inequality using the criteria presented in
the {@link java.lang.annotation.Annotation#equals(Object)} API docs.
+ *
+ * <p>
+ * This method is the negation of {@link
#eq(java.lang.annotation.Annotation, java.lang.annotation.Annotation)},
+ * which delegates to {@link
AnnotationUtils#equals(java.lang.annotation.Annotation,
java.lang.annotation.Annotation)}.
+ *
+ * @param a1 Annotation 1.
+ * @param a2 Annotation 2.
+ * @return <jk>true</jk> if the two annotations are not equal.
+ * @see #eq(java.lang.annotation.Annotation,
java.lang.annotation.Annotation)
+ * @see AnnotationUtils#equals(java.lang.annotation.Annotation,
java.lang.annotation.Annotation)
+ */
+ public static boolean ne(java.lang.annotation.Annotation a1,
java.lang.annotation.Annotation a2) {
+ return !eq(a1, a2);
+ }
+
/**
* Tests two strings for case-insensitive equality, but gracefully
handles nulls.
*
@@ -520,13 +553,25 @@ public class Utils {
}
/**
- * Shortcut for calling {@link Objects#hash(Object...)}.
+ * Calculates a hash code for the specified values.
+ *
+ * <p>
+ * This method handles annotations specially by delegating to {@link
AnnotationUtils#hash(Annotation)}
+ * to ensure consistent hashing according to the {@link
java.lang.annotation.Annotation#hashCode()} contract.
+ * For non-annotation values, it uses {@link Objects#hashCode(Object)}.
*
* @param values The values to hash.
* @return A hash code value for the given values.
+ * @see AnnotationUtils#hash(Annotation)
*/
public static final int hash(Object...values) {
- return Objects.hash(values);
+ if (values == null)
+ return 0;
+ var result = 1;
+ for (var value : values) {
+ result = 31 * result + (value instanceof
java.lang.annotation.Annotation ?
AnnotationUtils.hash((java.lang.annotation.Annotation)value) :
Objects.hashCode(value));
+ }
+ return result;
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
index 2c36a6a5bf..6f098f2641 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/BeanPropertyMeta.java
@@ -81,11 +81,11 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
/**
* Sets the bean registry to use with this bean property.
*
- * @param beanRegistry The bean registry to use with this bean
property.
+ * @param value The bean registry to use with this bean
property.
* @return This object.
*/
- public Builder beanRegistry(BeanRegistry beanRegistry) {
- this.beanRegistry = beanRegistry;
+ public Builder beanRegistry(BeanRegistry value) {
+ this.beanRegistry = value;
return this;
}
@@ -99,33 +99,33 @@ public class BeanPropertyMeta implements
Comparable<BeanPropertyMeta> {
/**
* Sets the original bean property that this one is overriding.
*
- * @param delegateFor The original bean property that this one
is overriding.
+ * @param value The original bean property that this one is
overriding.
* @return This object.
*/
- public Builder delegateFor(BeanPropertyMeta delegateFor) {
- this.delegateFor = delegateFor;
+ public Builder delegateFor(BeanPropertyMeta value) {
+ this.delegateFor = value;
return this;
}
/**
* Sets the overridden value of this bean property.
*
- * @param overrideValue The overridden value of this bean
property.
+ * @param value The overridden value of this bean property.
* @return This object.
*/
- public Builder overrideValue(Object overrideValue) {
- this.overrideValue = overrideValue;
+ public Builder overrideValue(Object value) {
+ this.overrideValue = value;
return this;
}
/**
* Sets the raw metadata type for this bean property.
*
- * @param rawMetaType The raw metadata type for this bean
property.
+ * @param value The raw metadata type for this bean property.
* @return This object.
*/
- public Builder rawMetaType(ClassMeta<?> rawMetaType) {
- this.rawTypeMeta = rawMetaType;
+ public Builder rawMetaType(ClassMeta<?> value) {
+ this.rawTypeMeta = value;
this.typeMeta = rawTypeMeta;
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
index d52f4abb0f..da8a5ac6c7 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/annotation/AnnotationImpl.java
@@ -81,7 +81,7 @@ public class AnnotationImpl implements Annotation {
public boolean equals(Object o) {
if (! annotationType.isInstance(o))
return false;
- return AnnotationUtils.equals(this, (Annotation)o);
+ return eq(this, (Annotation)o);
}
@Override /* Overridden from Object */
@@ -119,6 +119,6 @@ public class AnnotationImpl implements Annotation {
* This method must be called at the end of initialization to calculate
the hashCode one time.
*/
protected void postConstruct() {
- this.hashCode = AnnotationUtils.hashCode(this);
+ this.hashCode = AnnotationUtils.hash(this);
}
}
\ No newline at end of file
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/FileFinder.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/FileFinder.java
index d9f14e2968..be582380e9 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/FileFinder.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/FileFinder.java
@@ -142,12 +142,12 @@ public interface FileFinder {
/**
* Adds a file system directory to the lookup paths.
*
- * @param path The path relative to the working directory.
Must not be <jk>null</jk>
+ * @param value The path relative to the working directory.
Must not be <jk>null</jk>
* @return This object.
*/
- public Builder dir(String path) {
- assertArgNotNull("path", path);
- return path(Paths.get(".").resolve(path));
+ public Builder dir(String value) {
+ assertArgNotNull("value", value);
+ return path(Paths.get(".").resolve(value));
}
/**
@@ -185,11 +185,11 @@ public interface FileFinder {
/**
* Adds a file system directory to the lookup paths.
*
- * @param path The directory path.
+ * @param value The directory path.
* @return This object.
*/
- public Builder path(Path path) {
- roots.add(new LocalDir(path));
+ public Builder path(Path value) {
+ roots.add(new LocalDir(value));
return this;
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/Messages.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/Messages.java
index b113ecf94e..f5d1b609c5 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/Messages.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/cp/Messages.java
@@ -174,26 +174,26 @@ public class Messages extends ResourceBundle {
/**
* Specifies the locale.
*
- * @param locale
+ * @param value
* The locale.
* If <jk>null</jk>, the default locale is used.
* @return This object.
*/
- public Builder locale(Locale locale) {
- this.locale = locale == null ? Locale.getDefault() :
locale;
+ public Builder locale(Locale value) {
+ this.locale = value == null ? Locale.getDefault() :
value;
return this;
}
/**
* Specifies the locale.
*
- * @param locale
+ * @param value
* The locale.
* If <jk>null</jk>, the default locale is used.
* @return This object.
*/
- public Builder locale(String locale) {
- return locale(locale == null ? null :
Locale.forLanguageTag(locale));
+ public Builder locale(String value) {
+ return locale(value == null ? null :
Locale.forLanguageTag(value));
}
/**
@@ -222,24 +222,24 @@ public class Messages extends ResourceBundle {
/**
* Specifies the bundle name (e.g. <js>"Messages"</js>).
*
- * @param name
+ * @param value
* The bundle name.
* <br>If <jk>null</jk>, the forClass class name is used.
* @return This object.
*/
- public Builder name(String name) {
- this.name = isEmpty(name) ? forClass.getSimpleName() :
name;
+ public Builder name(String value) {
+ this.name = isEmpty(value) ? forClass.getSimpleName() :
value;
return this;
}
/**
* Adds a parent bundle.
*
- * @param parent The parent bundle. Can be <jk>null</jk>.
+ * @param value The parent bundle. Can be <jk>null</jk>.
* @return This object.
*/
- public Builder parent(Messages parent) {
- this.parent = parent;
+ public Builder parent(Messages value) {
+ this.parent = value;
return this;
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 8a59079893..27c09d580e 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -969,11 +969,11 @@ public class RestContext extends Context {
* <li class='jm'>{@link #config()}
* </ul>
*
- * @param config The new config file.
+ * @param value The new config file.
* @return This object.
*/
- public Builder config(Config config) {
- this.config = config;
+ public Builder config(Config value) {
+ this.config = value;
return this;
}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/staticfile/StaticFiles.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/staticfile/StaticFiles.java
index 35b04b8c66..4010806ace 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/staticfile/StaticFiles.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/staticfile/StaticFiles.java
@@ -153,22 +153,22 @@ public interface StaticFiles extends FileFinder {
/**
* Replaces the MIME types registry used for determining
content types.
*
- * @param mimeTypes The new MIME types registry.
+ * @param value The new MIME types registry.
* @return This object.
*/
- public Builder mimeTypes(MimeTypeDetector mimeTypes) {
- this.mimeTypes = mimeTypes;
+ public Builder mimeTypes(MimeTypeDetector value) {
+ this.mimeTypes = value;
return this;
}
/**
* Adds a file system directory to the lookup paths.
*
- * @param path The directory path.
+ * @param value The directory path.
* @return This object.
*/
- public Builder path(Path path) {
- fileFinder.path(path);
+ public Builder path(Path value) {
+ fileFinder.path(value);
return this;
}