1919
2020import java .io .IOException ;
2121import java .io .InputStream ;
22+ import java .util .List ;
2223import java .util .Properties ;
2324
2425import org .slf4j .Logger ;
@@ -59,6 +60,8 @@ private Configuration() {
5960 }
6061
6162 /**
63+ * Retrieve the singleton instance of the Configuration class
64+ *
6265 * @return The singleton instance of the Configuration class.
6366 */
6467 public static Configuration getInstance () {
@@ -69,6 +72,8 @@ public static Configuration getInstance() {
6972 }
7073
7174 /**
75+ * Retrieve the value of a configuration property by its name
76+ *
7277 * @param propertyName The name of the configuration property to retrieve.
7378 * @return The value of the given property name, or null if it wasn't found.
7479 */
@@ -77,6 +82,9 @@ public String getProperty(final String propertyName) {
7782 }
7883
7984 /**
85+ * Retrieve the value of a configuration property by its name;
86+ * return a default value if was not found
87+ *
8088 * @param propertyName The name of the configuration property to retrieve.
8189 * @param defaultValue The default value to return, if the property isn't found.
8290 * @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)
8593 return System .getProperty (propertyName , properties == null ? defaultValue : properties .getProperty (propertyName , defaultValue ));
8694 }
8795
96+ /**
97+ * Retrieve the value of the first found configuration property from a list
98+ * of names; return a default value if none are found.
99+ * <p>
100+ * This method checks each property name in the provided list in order.
101+ * If a property name is not found, it moves on to the next one.
102+ * If a property name is found, its value is returned.
103+ * If none of the property names are found, the provided default value is returned.
104+ *
105+ * @param propertyNames An ordered list of property names to check.
106+ * @param defaultValue The default value to return if none of the property names are found.
107+ * @return The value of the first found property name, or {@code defaultValue} if none are found.
108+ */
109+ public String getProperty (final List <String > propertyNames , final String defaultValue ) {
110+ if (propertyNames != null ) {
111+ for (String propertyName : propertyNames ) {
112+ String value = getProperty (propertyName );
113+ if (value != null ) {
114+ return value ;
115+ }
116+ }
117+ }
118+ return defaultValue ;
119+ }
120+
88121 /**
89122 * Tries to load properties from the CLASSPATH, using the provided filename, ignoring errors
90123 * encountered during the process (e.g., the properties file doesn't exist, etc.).
0 commit comments