Class PropertySet


  • public final class PropertySet
    extends java.lang.Object
    A map of key-value properties.

    This class represents a map of key to value. Multiple values may be associated with each key.

    This class is generally created by reading an INI or properties file. See IniFile and PropertiesFile.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.google.common.collect.ImmutableMap<java.lang.String,​java.lang.String> asMap()
      Returns the property set as a map, throwing an exception if any key has multiple values.
      com.google.common.collect.ImmutableListMultimap<java.lang.String,​java.lang.String> asMultimap()
      Returns the property set as a multimap.
      PropertySet combinedWith​(PropertySet other)
      Combines this property set with another.
      boolean contains​(java.lang.String key)
      Checks if this property set contains the specified key.
      static PropertySet empty()
      Obtains an empty property set.
      boolean equals​(java.lang.Object obj)
      Checks if this property set equals another.
      int hashCode()
      Returns a suitable hash code for the property set.
      boolean isEmpty()
      Checks if this property set is empty.
      com.google.common.collect.ImmutableSet<java.lang.String> keys()
      Returns the set of keys of this property set.
      static PropertySet of​(com.google.common.collect.Multimap<java.lang.String,​java.lang.String> keyValues)
      Obtains an instance from a map allowing for multiple values for each key.
      static PropertySet of​(java.util.Map<java.lang.String,​java.lang.String> keyValues)
      Obtains an instance from a map.
      PropertySet overrideWith​(PropertySet other)
      Overrides this property set with another.
      java.lang.String toString()
      Returns a string describing the property set.
      java.lang.String value​(java.lang.String key)
      Gets a single value from this property set.
      com.google.common.collect.ImmutableList<java.lang.String> valueList​(java.lang.String key)
      Gets the list of values associated with the specified key.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • empty

        public static PropertySet empty()
        Obtains an empty property set.

        The result contains no properties.

        Returns:
        an empty property set
      • of

        public static PropertySet of​(java.util.Map<java.lang.String,​java.lang.String> keyValues)
        Obtains an instance from a map.

        The returned instance will have one value for each key.

        Parameters:
        keyValues - the key-values to create the instance with
        Returns:
        the property set
      • of

        public static PropertySet of​(com.google.common.collect.Multimap<java.lang.String,​java.lang.String> keyValues)
        Obtains an instance from a map allowing for multiple values for each key.

        The returned instance may have more than one value for each key.

        Parameters:
        keyValues - the key-values to create the instance with
        Returns:
        the property set
      • keys

        public com.google.common.collect.ImmutableSet<java.lang.String> keys()
        Returns the set of keys of this property set.

        The iteration order of the map matches that of the input data.

        Returns:
        the set of keys
      • asMultimap

        public com.google.common.collect.ImmutableListMultimap<java.lang.String,​java.lang.String> asMultimap()
        Returns the property set as a multimap.

        The iteration order of the map matches that of the input data.

        Returns:
        the key-value map
      • asMap

        public com.google.common.collect.ImmutableMap<java.lang.String,​java.lang.String> asMap()
        Returns the property set as a map, throwing an exception if any key has multiple values.

        The iteration order of the map matches that of the input data.

        Returns:
        the key-value map
      • isEmpty

        public boolean isEmpty()
        Checks if this property set is empty.
        Returns:
        true if the set is empty
      • contains

        public boolean contains​(java.lang.String key)
        Checks if this property set contains the specified key.
        Parameters:
        key - the key name
        Returns:
        true if the key exists
      • value

        public java.lang.String value​(java.lang.String key)
        Gets a single value from this property set.

        This returns the value associated with the specified key. If more than one value, or no value, is associated with the key an exception is thrown.

        Parameters:
        key - the key name
        Returns:
        the value
        Throws:
        java.lang.IllegalArgumentException - if the key does not exist, or if more than one value is associated
      • valueList

        public com.google.common.collect.ImmutableList<java.lang.String> valueList​(java.lang.String key)
        Gets the list of values associated with the specified key.

        A key-values instance may contain multiple values for each key. This method returns that list of values. The iteration order of the map matches that of the input data. The returned list may be empty.

        Parameters:
        key - the key name
        Returns:
        the list of values associated with the key
      • combinedWith

        public PropertySet combinedWith​(PropertySet other)
        Combines this property set with another.

        This property set takes precedence. Any order of any additional keys will be retained, with those keys located after the base set of keys.

        Parameters:
        other - the other property set
        Returns:
        the combined property set
      • overrideWith

        public PropertySet overrideWith​(PropertySet other)
        Overrides this property set with another.

        The specified property set takes precedence. The order of any existing keys will be retained, with the value replaced. Any order of any additional keys will be retained, with those keys located after the base set of keys.

        Parameters:
        other - the other property set
        Returns:
        the combined property set
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if this property set equals another.

        The comparison checks the content.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other section, null returns false
        Returns:
        true if equal
      • hashCode

        public int hashCode()
        Returns a suitable hash code for the property set.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • toString

        public java.lang.String toString()
        Returns a string describing the property set.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the descriptive string