Class KiwiProperties


  • public class KiwiProperties
    extends Object
    Utility methods for making it easier to create and work with Properties instances.
    • Constructor Detail

      • KiwiProperties

        public KiwiProperties()
    • Method Detail

      • newProperties

        public static Properties newProperties​(Object... items)
        Crates a mutable Properties 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 mutable Properties 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 mutable Properties 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 a Properties instance from a Map a one-liner. Also, restricts the map to string keys and values. Creates a mutable Properties 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: "Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are not Strings. The setProperty 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 mutable Properties 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 null
        IllegalArgumentException - 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.