Skip to content
Snippets Groups Projects
Commit 50bc3d2d authored by felmer's avatar felmer
Browse files

SP-326, BIS-217: Add method getList() to PropertyUtils. Tests written.

SVN: 27240
parent 36f5724d
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
package ch.systemsx.cisd.common.properties;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
......@@ -214,6 +215,26 @@ public final class PropertyUtils
}
return Arrays.asList(items);
}
/**
* Returns list of comma separated values at the specific property key. Each element is trimmed.
*
* @return an empty list if the property is undefined or an empty string.
*/
public static List<String> getList(Properties properties, String propertyKey)
{
List<String> result = new ArrayList<String>();
String property = PropertyUtils.getProperty(properties, propertyKey);
if (StringUtils.isNotBlank(property))
{
String[] splittedProperty = property.split(",");
for (String term : splittedProperty)
{
result.add(term.trim());
}
}
return result;
}
/**
* Looks up given <var>propertyKey</var> in given <var>properties</var>.
......
......@@ -234,4 +234,30 @@ public final class PropertyUtilsTest extends AbstractFileSystemTestCase
assertEquals(4, PropertyUtils.getPosLong(properties, key, 4));
assertEquals(-7, PropertyUtils.getLong(properties, key, 4));
}
@Test
public void testGetList()
{
Properties properties = new Properties();
properties.setProperty("key", " a, gamma, Einstein");
assertEquals("[a, gamma, Einstein]", PropertyUtils.getList(properties, "key").toString());
}
@Test
public void testGetListForUndefinedProperty()
{
Properties properties = new Properties();
assertEquals("[]", PropertyUtils.getList(properties, "key").toString());
}
@Test
public void testGetListForEmptyProperty()
{
Properties properties = new Properties();
properties.setProperty("key", " ");
assertEquals("[]", PropertyUtils.getList(properties, "key").toString());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment