Package org.kiwiproject.collect
Class KiwiProperties
java.lang.Object
org.kiwiproject.collect.KiwiProperties
Utility methods for making it easier to create and work with
Properties instances.-
Method Summary
Modifier and TypeMethodDescriptionstatic PropertiesnewProperties(Object... items) Crates a mutablePropertiesinstance by parsing the items argument in pairs.static PropertiesnewProperties(String... items) Creates a mutablePropertiesinstance by parsing the items argument in pairs.static PropertiesnewProperties(List<String> items) Creates a mutablePropertiesinstance by parsing the items argument in pairs from the list.static PropertiesnewProperties(Map<String, String> map) Makes creating aPropertiesinstance from aMapa one-liner.static PropertiesnewPropertiesFromStringPairs(List<List<String>> items) Creates a mutablePropertiesinstance from each key/value pair list inside the outer list.
-
Method Details
-
newProperties
Crates a mutablePropertiesinstance 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
Propertiesis designed to only have string keys and values. The values are always converted to strings before putting them in the properties.
-
newProperties
Creates a mutablePropertiesinstance 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
Creates a mutablePropertiesinstance 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
Makes creating aPropertiesinstance from aMapa one-liner. Also, restricts the map to string keys and values. Creates a mutablePropertiesinstance.- 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
Hashtableand the JavaDoc states: "BecausePropertiesinherits fromHashtable, theputandputAllmethods can be applied to aPropertiesobject. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are notStrings. ThesetPropertymethod 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
Creates a mutablePropertiesinstance 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.
-