diff --git a/archaius2-api/src/main/java/com/netflix/archaius/api/Config.java b/archaius2-api/src/main/java/com/netflix/archaius/api/Config.java index 53aa3fb53..7a28cf5f1 100644 --- a/archaius2-api/src/main/java/com/netflix/archaius/api/Config.java +++ b/archaius2-api/src/main/java/com/netflix/archaius/api/Config.java @@ -135,14 +135,26 @@ default boolean instrumentationEnabled() { /** * Get the property as a list. Depending on the underlying implementation the list - * may be derived from a comma delimited string or from an actual list structure. - * @param key - * @return + * may be derived from a comma-delimited string or from an actual list structure. + * @deprecated Use {@link #getList(String, Class)} instead. */ List getList(String key); - + + /** + * Get the property as a list. Depending on the underlying implementation the list + * may be derived from a comma-delimited string or from an actual list structure. + */ List getList(String key, Class type); - + + /** + * Get the property as a list. Depending on the underlying implementation the list + * may be derived from a comma-delimited string or from an actual list structure. + * This method is inherently unsafe and should be used with caution. The type of the list may change + * depending on whether the key is defined or not, because the parser can't know the type of the defaultValue's + * elements. + * @deprecated Use {@link #getList(String, Class)} instead. + */ + @Deprecated List getList(String key, List defaultValue); /** diff --git a/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyContainer.java b/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyContainer.java index e11cc7240..40b74e646 100644 --- a/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyContainer.java +++ b/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyContainer.java @@ -26,6 +26,7 @@ * of Property are non-blocking and optimize updating property values * in the background so as not to incur any overhead during hot call * paths. + * @deprecated Use {@link Property} instead. */ @Deprecated public interface PropertyContainer { diff --git a/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyFactory.java b/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyFactory.java index 9a8fa0d6f..924ba0911 100644 --- a/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyFactory.java +++ b/archaius2-api/src/main/java/com/netflix/archaius/api/PropertyFactory.java @@ -15,16 +15,20 @@ */ package com.netflix.archaius.api; +import java.lang.reflect.Type; + /** * Factory of Property objects. * * @see Property - * @deprecated Deprecated in favor of using PropertyRepository + * @deprecated Deprecated in favor of {@link PropertyRepository} */ @Deprecated public interface PropertyFactory extends PropertyRepository { /** - * Create a property for the property name. + * Create a property for the property name. + * @deprecated Use {@link PropertyRepository#get(String, Type)} instead. */ + @Deprecated PropertyContainer getProperty(String propName); } diff --git a/archaius2-commons-configuration/src/main/java/com/netflix/archaius/commons/CommonsToConfig.java b/archaius2-commons-configuration/src/main/java/com/netflix/archaius/commons/CommonsToConfig.java index 9333fc038..e8f6e0895 100644 --- a/archaius2-commons-configuration/src/main/java/com/netflix/archaius/commons/CommonsToConfig.java +++ b/archaius2-commons-configuration/src/main/java/com/netflix/archaius/commons/CommonsToConfig.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.function.BiConsumer; import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.lang.StringUtils; @@ -59,16 +58,18 @@ public Iterator getKeys() { @Override public List getList(String key, Class type) { - List value = config.getList(key); + List value = config.getList(key); if (value == null) { return notFound(key); } -; - List result = new ArrayList(); + + List result = new ArrayList<>(); for (Object part : value) { if (type.isInstance(part)) { - result.add((T)part); + //noinspection unchecked + result.add((T) part); } else if (part instanceof String) { + //noinspection deprecation result.add(getDecoder().decode(type, (String) part)); } else { throw new UnsupportedOperationException( @@ -79,8 +80,8 @@ public List getList(String key, Class type) { } @Override - public List getList(String key) { - List value = config.getList(key); + public List getList(String key) { + List value = config.getList(key); if (value == null) { return notFound(key); } @@ -89,28 +90,24 @@ public List getList(String key) { @Override public String getString(String key, String defaultValue) { - List value = config.getList(key); + List value = config.getList(key); if (value == null) { return notFound(key, defaultValue != null ? getStrInterpolator().create(getLookup()).resolve(defaultValue) : null); } - List interpolatedResult = new ArrayList<>(); - for (Object part : value) { - if (part instanceof String) { - interpolatedResult.add(getStrInterpolator().create(getLookup()).resolve(part.toString())); - } else { - throw new UnsupportedOperationException( - "Property values other than String not supported"); - } - } - return StringUtils.join(interpolatedResult, getListDelimiter()); + return interpolateAndConcat(value); } @Override public String getString(String key) { - List value = config.getList(key); + List value = config.getList(key); if (value == null) { return notFound(key); } + return interpolateAndConcat(value); + } + + + private String interpolateAndConcat(List value) { List interpolatedResult = new ArrayList<>(); for (Object part : value) { if (part instanceof String) {