Package org.kiwiproject.collect
Class KiwiProperties
- java.lang.Object
-
- org.kiwiproject.collect.KiwiProperties
-
public class KiwiProperties extends Object
Utility methods for making it easier to create and work withProperties
instances.
-
-
Constructor Summary
Constructors Constructor Description KiwiProperties()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Properties
newProperties(Object... items)
Crates a mutableProperties
instance by parsing the items argument in pairs.static Properties
newProperties(String... items)
Creates a mutableProperties
instance by parsing the items argument in pairs.static Properties
newProperties(List<String> items)
Creates a mutableProperties
instance by parsing the items argument in pairs from the list.static Properties
newProperties(Map<String,String> map)
Makes creating aProperties
instance from aMap
a one-liner.static Properties
newPropertiesFromStringPairs(List<List<String>> items)
Creates a mutableProperties
instance from each key/value pair list inside the outer list.
-
-
-
Method Detail
-
newProperties
public static Properties newProperties(Object... items)
Crates a mutableProperties
instance by parsing the items argument in pairs. The items argument contains keys and values in the form:key-1, value-1, key-2, value-2, ... , key-N, value-N
- Parameters:
items
- the items containing keys and values, in pairs- Returns:
- a new Properties instance with data from items
- Throws:
NullPointerException
- if any of the items is null- Implementation Note:
- Please note that even though this method accepts objects, you should really only put strings in here,
due to the way
Properties
is designed to only have string keys and values. The values are always converted to strings before putting them in the properties.
-
newProperties
public static Properties newProperties(String... items)
Creates a mutableProperties
instance by parsing the items argument in pairs. The items argument contains keys and values in the form:key-1, value-1, key-2, value-2, ... , key-N, value-N
- Parameters:
items
- the items containing keys and values, in pairs- Returns:
- a new Properties instance with data from items
- Throws:
NullPointerException
- if any of the items is null
-
newProperties
public static Properties newProperties(List<String> items)
Creates a mutableProperties
instance by parsing the items argument in pairs from the list.- Parameters:
items
- the items containing keys and values, in pairs- Returns:
- a new Properties instance with data from items
- Throws:
NullPointerException
- if any of the items is null
-
newProperties
public static Properties newProperties(Map<String,String> map)
Makes creating aProperties
instance from aMap
a one-liner. Also, restricts the map to string keys and values. Creates a mutableProperties
instance.- Parameters:
map
- the source map- Returns:
- a new Properties instance with data from the map
- Throws:
NullPointerException
- if any of the items is null- Implementation Note:
- The reason this method restricts the map keys and values to strings is because Properties is derived
from
Hashtable
and the JavaDoc states: "BecauseProperties
inherits fromHashtable
, theput
andputAll
methods can be applied to aProperties
object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are notStrings
. ThesetProperty
method should be used instead." This of course is simply poor design (they should have used composition and hidden the internal storage details instead of extending Hashtable).
-
newPropertiesFromStringPairs
public static Properties newPropertiesFromStringPairs(List<List<String>> items)
Creates a mutableProperties
instance from each key/value pair list inside the outer list. The items argument must contain keys and values in teh form:[ [key-1, value-1], [key-2, value-2], ... , [key-N, value-N]
- Parameters:
items
- the items list containing a series of two-items key/value pair lists- Returns:
- a new Properties instance with data from items
- Throws:
NullPointerException
- if any of the items is nullIllegalArgumentException
- if any of the key/value pair lists do not have at least two elements- Implementation Note:
- only the first and second elements of the key/value pair sub-lists are used when creating the Properties instance. Thus while it does not make much sense, this method will not throw an exception if the sub-lists contain more than two elements.
-
-