From 3a196129a06c35e110863bb007530c1507791cb6 Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Mon, 5 May 2025 23:37:48 +0100 Subject: [PATCH 1/2] Add getProperty(List propertyNames) Add a new method to return the value of the first found configuration property from a list of names. Can be useful to use with deprecated names. Signed-off-by: Arthit Suriyawongkul --- src/main/java/org/spdx/Configuration.java | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/spdx/Configuration.java b/src/main/java/org/spdx/Configuration.java index 43e3de08..4688de9c 100644 --- a/src/main/java/org/spdx/Configuration.java +++ b/src/main/java/org/spdx/Configuration.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.List; import java.util.Properties; import org.slf4j.Logger; @@ -59,6 +60,8 @@ private Configuration() { } /** + * Retrieve the singleton instance of the Configuration class + * * @return The singleton instance of the Configuration class. */ public static Configuration getInstance() { @@ -69,6 +72,8 @@ public static Configuration getInstance() { } /** + * Retrieve the value of a configuration property by its name + * * @param propertyName The name of the configuration property to retrieve. * @return The value of the given property name, or null if it wasn't found. */ @@ -77,6 +82,9 @@ public String getProperty(final String propertyName) { } /** + * Retrieve the value of a configuration property by its name; + * return a default value if was not found + * * @param propertyName The name of the configuration property to retrieve. * @param defaultValue The default value to return, if the property isn't found. * @return The value of the given property name, or defaultValue if it wasn't found. @@ -85,6 +93,31 @@ public String getProperty(final String propertyName, final String defaultValue) return System.getProperty(propertyName, properties == null ? defaultValue : properties.getProperty(propertyName, defaultValue)); } + /** + * Retrieve the value of the first found configuration property from a list + * of names; return a default value if none are found. + *

+ * This method checks each property name in the provided list in order. + * If a property name is not found, it moves on to the next one. + * If a property name is found, its value is returned. + * If none of the property names are found, the provided default value is returned. + * + * @param propertyNames An ordered list of property names to check. + * @param defaultValue The default value to return if none of the property names are found. + * @return The value of the first found property name, or {@code defaultValue} if none are found. + */ + public String getProperty(final List propertyNames, final String defaultValue) { + if (propertyNames != null) { + for (String propertyName : propertyNames) { + String value = getProperty(propertyName); + if (value != null) { + return value; + } + } + } + return defaultValue; + } + /** * Tries to load properties from the CLASSPATH, using the provided filename, ignoring errors * encountered during the process (e.g., the properties file doesn't exist, etc.). From 9cc5c6c44ab87b010337e75f06e2cef23b2fe75a Mon Sep 17 00:00:00 2001 From: Arthit Suriyawongkul Date: Tue, 6 May 2025 03:45:21 +0100 Subject: [PATCH 2/2] Update getProperty(list) Javadoc Signed-off-by: Arthit Suriyawongkul --- src/main/java/org/spdx/Configuration.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/spdx/Configuration.java b/src/main/java/org/spdx/Configuration.java index 4688de9c..55ed72e7 100644 --- a/src/main/java/org/spdx/Configuration.java +++ b/src/main/java/org/spdx/Configuration.java @@ -95,15 +95,15 @@ public String getProperty(final String propertyName, final String defaultValue) /** * Retrieve the value of the first found configuration property from a list - * of names; return a default value if none are found. + * of names; return a default value if none are found *

* This method checks each property name in the provided list in order. * If a property name is not found, it moves on to the next one. * If a property name is found, its value is returned. * If none of the property names are found, the provided default value is returned. * - * @param propertyNames An ordered list of property names to check. - * @param defaultValue The default value to return if none of the property names are found. + * @param propertyNames An ordered list of configuration property names to retrieve. + * @param defaultValue The default value to return if none of the properties are found. * @return The value of the first found property name, or {@code defaultValue} if none are found. */ public String getProperty(final List propertyNames, final String defaultValue) {