Skip to content

Commit

Permalink
Merge pull request #733 from Netflix/warnings-cleanup
Browse files Browse the repository at this point in the history
Cleanup a few compiler warnings and improve some javadocs.
  • Loading branch information
rgallardo-netflix authored Sep 25, 2024
2 parents 8eb1958 + 8f1bb90 commit da35535
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
22 changes: 17 additions & 5 deletions archaius2-api/src/main/java/com/netflix/archaius/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
<T> List<T> getList(String key, Class<T> 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);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,16 +58,18 @@ public Iterator<String> getKeys() {

@Override
public <T> List<T> getList(String key, Class<T> type) {
List value = config.getList(key);
List<?> value = config.getList(key);
if (value == null) {
return notFound(key);
}
;
List<T> result = new ArrayList<T>();

List<T> 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(
Expand All @@ -79,8 +80,8 @@ public <T> List<T> getList(String key, Class<T> 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);
}
Expand All @@ -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<String> 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<String> interpolatedResult = new ArrayList<>();
for (Object part : value) {
if (part instanceof String) {
Expand Down

0 comments on commit da35535

Please sign in to comment.