com.linkedin.r2.util.ConfigValueExtractor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of r2-core Show documentation
Show all versions of r2-core Show documentation
Pegasus is a framework for building robust, scalable service architectures using dynamic discovery and simple asychronous type-checked REST + JSON APIs.
The newest version!
package com.linkedin.r2.util;
import java.util.ArrayList;
import java.util.List;
/**
* @author kparikh
*/
public class ConfigValueExtractor
{
/**
* Converts a property value that logically represents a List into a List, regardless of how it's been expressed in
* the config.
* @param propertyValue the value we want to extract as a List
* @param listSeparator the separator between values in the config
* @return a list of the property values, or an empty list if propertyValue is null
*/
public static List buildList(Object propertyValue, String listSeparator)
{
List valueList = new ArrayList();
if (propertyValue != null)
{
if (propertyValue instanceof List>)
{
@SuppressWarnings("unchecked")
List list = (List)propertyValue;
valueList.addAll(list);
}
else
{
// list was expressed as a String in the config
String propertyValueString = (String)propertyValue;
if (listSeparator == null)
{
throw new IllegalArgumentException("The separator cannot be null!");
}
for (String value: propertyValueString.split(listSeparator))
{
if (!value.isEmpty())
{
valueList.add(value.trim());
}
}
}
}
return valueList;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy