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 c8691d77df Marshall module improvements
c8691d77df is described below
commit c8691d77df00a9fe5ed69aa1f4faddb08754f9bb
Author: James Bognar <[email protected]>
AuthorDate: Thu Dec 11 12:15:15 2025 -0500
Marshall module improvements
---
.../{ReadOnlySource.java => FunctionalSource.java} | 24 ++++++++++-------
.../apache/juneau/commons/settings/MapSource.java | 30 ++++++++++------------
.../juneau/commons/settings/SettingSource.java | 10 ++++----
.../apache/juneau/commons/settings/Settings.java | 21 +++++++++++----
.../apache/juneau/commons/utils/ClassUtils.java | 1 +
.../juneau/commons/utils/CollectionUtils.java | 15 +++++++++++
6 files changed, 66 insertions(+), 35 deletions(-)
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/ReadOnlySource.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/FunctionalSource.java
similarity index 82%
rename from
juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/ReadOnlySource.java
rename to
juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/FunctionalSource.java
index 25f0a576d0..11bdc62d6b 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/ReadOnlySource.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/FunctionalSource.java
@@ -16,6 +16,7 @@
*/
package org.apache.juneau.commons.settings;
+import static org.apache.juneau.commons.utils.ThrowableUtils.*;
import static org.apache.juneau.commons.utils.Utils.*;
import java.util.*;
@@ -42,16 +43,16 @@ import java.util.function.*;
* <h5 class='section'>Example:</h5>
* <p class='bjava'>
* <jc>// Create a read-only source from System.getProperty</jc>
- * ReadOnlySource <jv>sysProps</jv> = <jk>new</jk> ReadOnlySource(x ->
System.getProperty(x));
+ * FunctionalSource <jv>sysProps</jv> = <jk>new</jk> FunctionalSource(x
-> System.getProperty(x));
*
* <jc>// Create a read-only source from System.getenv</jc>
- * ReadOnlySource <jv>envVars</jv> = <jk>new</jk> ReadOnlySource(x ->
System.getenv(x));
+ * FunctionalSource <jv>envVars</jv> = <jk>new</jk> FunctionalSource(x
-> System.getenv(x));
*
* <jc>// Add to Settings</jc>
* Settings.<jsf>get</jsf>().addSource(<jv>sysProps</jv>);
* </p>
*/
-public class ReadOnlySource implements SettingSource {
+public class FunctionalSource implements SettingSource {
private final Function<String,String> function;
@@ -60,7 +61,7 @@ public class ReadOnlySource implements SettingSource {
*
* @param function The function to delegate property lookups to. Must
not be <c>null</c>.
*/
- public ReadOnlySource(Function<String,String> function) {
+ public FunctionalSource(Function<String,String> function) {
this.function = function;
}
@@ -86,7 +87,7 @@ public class ReadOnlySource implements SettingSource {
* @return <c>false</c>
*/
@Override
- public boolean canWrite() {
+ public boolean isWriteable() {
return false;
}
@@ -97,7 +98,9 @@ public class ReadOnlySource implements SettingSource {
* @param value The property value (ignored).
*/
@Override
- public void set(String name, String value) {}
+ public void set(String name, String value) {
+ throw illegalArg("Attempting to set a value on a read-only
source.");
+ }
/**
* No-op since this source is read-only.
@@ -105,12 +108,15 @@ public class ReadOnlySource implements SettingSource {
* @param name The property name (ignored).
*/
@Override
- public void unset(String name) {}
+ public void unset(String name) {
+ throw illegalArg("Attempting to unset a value on a read-only
source.");
+ }
/**
* No-op since this source is read-only.
*/
@Override
- public void clear() {}
-
+ public void clear() {
+ throw illegalArg("Attempting to clear a read-only source.");
+ }
}
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/MapSource.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/MapSource.java
index f7ed272e44..986fbf8d1f 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/MapSource.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/MapSource.java
@@ -16,6 +16,7 @@
*/
package org.apache.juneau.commons.settings;
+import static org.apache.juneau.commons.utils.AssertionUtils.*;
import static org.apache.juneau.commons.utils.Utils.*;
import java.util.*;
@@ -99,8 +100,7 @@ public class MapSource implements SettingSource {
*/
@Override
public void set(String key, String value) {
- if (! canWrite())
- return;
+ assertWriteable("Attempting to set a value on a read-only map
source.");
var m = map.get();
if (m == null) {
var newMap = new
ConcurrentHashMap<String,Optional<String>>();
@@ -118,23 +118,12 @@ public class MapSource implements SettingSource {
*/
@Override
public void clear() {
- if (! canWrite())
- return;
+ assertWriteable("Attempting to update a read-only map source.");
var m = map.get();
if (m != null)
m.clear();
}
- /**
- * Returns <c>true</c> since this source is writable.
- *
- * @return <c>true</c>
- */
- @Override
- public boolean canWrite() {
- return true;
- }
-
/**
* Removes a setting from this source.
*
@@ -147,10 +136,19 @@ public class MapSource implements SettingSource {
*/
@Override
public void unset(String name) {
- if (! canWrite())
- return;
+ assertWriteable("Attempting to unset a value on a read-only map
source.");
var m = map.get();
if (m != null)
m.remove(name);
}
+
+ @Override
+ public boolean isWriteable() {
+ return true;
+ }
+
+ private void assertWriteable(String msg, Object...args) {
+ assertArg(isWriteable(), msg, args);
+ }
+
}
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/SettingSource.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/SettingSource.java
index 09b88f96d6..a5f4af9502 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/SettingSource.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/SettingSource.java
@@ -40,7 +40,7 @@ import java.util.*;
* <jv>source</jv>.set(<js>"my.property"</js>, <js>"value"</js>);
*
* <jc>// Create a read-only source from a function</jc>
- * ReadOnlySource <jv>readOnly</jv> = <jk>new</jk> ReadOnlySource(x ->
System.getProperty(x));
+ * FunctionalSource <jv>readOnly</jv> = <jk>new</jk> FunctionalSource(x
-> System.getProperty(x));
* </p>
*/
public interface SettingSource {
@@ -72,13 +72,13 @@ public interface SettingSource {
*
* @return <c>true</c> if this source is writable, <c>false</c>
otherwise.
*/
- boolean canWrite();
+ boolean isWriteable();
/**
* Sets a setting in this setting source.
*
* <p>
- * Should be a no-op if the source is not writable (i.e., {@link
#canWrite()} returns <c>false</c>).
+ * Should be a no-op if the source is not writable (i.e., {@link
#assertWriteable()} returns <c>false</c>).
*
* <p>
* Setting a value to <c>null</c> means that {@link #get(String)} will
return <c>Optional.empty()</c> for that key,
@@ -94,7 +94,7 @@ public interface SettingSource {
* Removes a setting from this setting source.
*
* <p>
- * Should be a no-op if the source is not writable (i.e., {@link
#canWrite()} returns <c>false</c>).
+ * Should be a no-op if the source is not writable (i.e., {@link
#assertWriteable()} returns <c>false</c>).
*
* <p>
* After calling this method, {@link #get(String)} will return
<c>null</c> for the specified key,
@@ -109,7 +109,7 @@ public interface SettingSource {
* Clears all settings from this setting source.
*
* <p>
- * Should be a no-op if the source is not writable (i.e., {@link
#canWrite()} returns <c>false</c>).
+ * Should be a no-op if the source is not writable (i.e., {@link
#assertWriteable()} returns <c>false</c>).
*
* <p>
* After calling this method, all keys will be removed from this
source, and {@link #get(String)} will
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
index b57b2d3188..a3e3fef582 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/settings/Settings.java
@@ -24,7 +24,6 @@ import java.net.*;
import java.nio.charset.*;
import java.nio.file.*;
import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
/**
@@ -97,8 +96,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
* <li><c>juneau.settings.disableGlobal</c> - If set to <c>true</c>,
prevents new global overrides
* from being set via {@link #setGlobal(String, String)}. Existing
global overrides will still be
* returned by {@link #get(String)} until explicitly removed.
+ * <p class='bnote'>
+ * Note: This property is read once at class
initialization time and cannot be changed at runtime.
+ * Changing the system property after the class has been
loaded will have no effect.
+ * </p>
* <li><c>juneau.settings.disableCustomSources</c> - If set to
<c>true</c>, prevents custom sources
* from being added via {@link #addSource(SettingSource)} or
{@link #setSources(SettingSource...)}.
+ * <p class='bnote'>
+ * Note: This property is read once at class
initialization time and cannot be changed at runtime.
+ * Changing the system property after the class has been
loaded will have no effect.
+ * </p>
* </ul>
*/
public class Settings {
@@ -121,12 +128,12 @@ public class Settings {
/**
* System property source that delegates to {@link
System#getProperty(String)}.
*/
- public static final SettingSource SYSTEM_PROPERTY_SOURCE = new
ReadOnlySource(x -> System.getProperty(x));
+ public static final SettingSource SYSTEM_PROPERTY_SOURCE = new
FunctionalSource(x -> System.getProperty(x));
/**
* System environment variable source that delegates to {@link
System#getenv(String)}.
*/
- public static final SettingSource SYSTEM_ENV_SOURCE = new
ReadOnlySource(x -> System.getenv(x));
+ public static final SettingSource SYSTEM_ENV_SOURCE = new
FunctionalSource(x -> System.getenv(x));
/**
* Returns properties for this Settings object itself.
@@ -135,10 +142,10 @@ public class Settings {
private static final Optional<String> initProperty(String property) {
var v = SYSTEM_PROPERTY_SOURCE.get(property);
if (v != null)
- return v;
+ return v; // Not testable
v = SYSTEM_ENV_SOURCE.get(property);
if (v != null)
- return v;
+ return v; // Not testable
return opte();
}
@@ -477,6 +484,10 @@ public class Settings {
return this;
}
+ public Settings addSource(FunctionalSource source) {
+ return addSource((SettingSource)source);
+ }
+
/**
* Sets the source list, replacing all existing sources.
*
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java
index b429c3038e..fd06112a93 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/ClassUtils.java
@@ -557,6 +557,7 @@ public class ClassUtils {
*
* @param t The type we're recursing.
* @param m Where the results are loaded.
+ * @return A map of class to type variable implementations.
*/
public static Map<Class<?>,Class<?>[]> findTypeVarImpls(Type t) {
Map<Class<?>,Class<?>[]> m = new LinkedHashMap<>();
diff --git
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/CollectionUtils.java
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/CollectionUtils.java
index b7f7b5b2c1..92b335a864 100644
---
a/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/CollectionUtils.java
+++
b/juneau-core/juneau-commons/src/main/java/org/apache/juneau/commons/utils/CollectionUtils.java
@@ -1711,6 +1711,21 @@ public class CollectionUtils {
return new LinkedHashSet<>(Arrays.asList(values));
}
+ /**
+ * Returns an empty immutable set.
+ *
+ * <p>
+ * This is a convenience method that returns {@link
Collections#emptySet()}.
+ *
+ * <h5 class='section'>Example:</h5>
+ * <p class='bjava'>
+ * Set<String> <jv>empty</jv> =
CollectionUtils.<jsf>sete</jsf>(); <jc>// Returns Collections.emptySet()</jc>
+ * </p>
+ *
+ * @param <T> The element type.
+ * @return An empty immutable set.
+ * @see Collections#emptySet()
+ */
public static <T> Set<T> sete() {
return Collections.emptySet();
}