Class PMap


  • public final class PMap
    extends Value
    An ordered map of Strings to Values.
    • Method Detail

      • get

        public Value get​(String key)
        Get the value for the given key, or null if the key does not exist.
        Parameters:
        key - map key
        Returns:
        mapped value or null
      • getBoolean

        public boolean getBoolean​(String key,
                                  boolean def)
        Get a boolean value from the map, returning a default value if the key is not mapped or mapped to a value that cannot be converted to a boolean.
        Parameters:
        key - map key
        def - default if unmapped or invalid
        Returns:
        value or default
      • getInt

        public int getInt​(String key,
                          int def)
        Get an integer value from the map, returning a default value if the key is not mapped or mapped to a value that cannot be converted to an integer.
        Parameters:
        key - map key
        def - default if unmapped or invalid
        Returns:
        value or default
      • getDouble

        public double getDouble​(String key,
                                double def)
        Get a double value from the map, returning a default value if the key is not mapped or mapped to a value that cannot be converted to a double.
        Parameters:
        key - map key
        def - default if unmapped or invalid
        Returns:
        value or default
      • getString

        public String getString​(String key,
                                String def)
        Get a String value from the map, returning a default value if the key is not mapped.
        Parameters:
        key - map key
        def - default if unmapped
        Returns:
        value or default
      • size

        public int size()
        Size of the map. This is the number of key-value pairs.
        Returns:
        size of the map
      • keys

        public List<String> keys()
        List of map keys. This is returned as a List as the keys are ordered.
        Returns:
        map keys
      • toString

        public String toString()
        Description copied from class: Value
        Values must override the default method to return a string representation that is immutable.
        Specified by:
        toString in class Value
        Returns:
        String representation
      • isEmpty

        public boolean isEmpty()
        Description copied from class: Value
        Check whether this Value is an empty value and has a zero length string representation. Subclasses may wish to override this for efficiency if the String representation is lazily created.
        Overrides:
        isEmpty in class Value
        Returns:
        boolean true if empty
      • equivalent

        public boolean equivalent​(Value arg)
        Description copied from class: Value
        Indicates whether some other Value is equivalent to this one. Unlike Value.equals(java.lang.Object) this method is not symmetric - a value of a different type might be equivalent to this without the other type considering the reverse to be true.

        The default implementation uses identity or String equality.

        Overrides:
        equivalent in class Value
        Parameters:
        arg - value to test for equivalence
        Returns:
        true if value is equivalent to this
      • hashCode

        public int hashCode()
        Description copied from class: Value
        Values must override the default hashcode method.
        Specified by:
        hashCode in class Value
        Returns:
        int hashcode
      • equals

        public boolean equals​(Object obj)
        Description copied from class: Value
        Values must override the default equals method. This method should only return true if the supplied Object is of the same type as the implementing Value. Values of an unknown type should be coerced before calling this method. This method does not have to guarantee that this.equals(that) == this.toString().equals(that.toString())
        Specified by:
        equals in class Value
        Returns:
        boolean
      • of

        public static PMap of​(String key,
                              Object value)
        Create a PMap with one mapping. Map values that are not Value types will be converted automatically.
        Parameters:
        key - map key
        value - mapped value
        Returns:
        new PMap
      • of

        public static PMap of​(String key1,
                              Object value1,
                              String key2,
                              Object value2)
        Create a PMap with two mappings. Map values that are not Value types will be converted automatically.
        Parameters:
        key1 - first map key
        value1 - first mapped value
        key2 - second map key
        value2 - second mapped value
        Returns:
        new PMap
      • of

        public static PMap of​(String key1,
                              Object value1,
                              String key2,
                              Object value2,
                              String key3,
                              Object value3)
        Create a PMap with three mappings. Map values that are not Value types will be converted automatically.
        Parameters:
        key1 - first map key
        value1 - first mapped value
        key2 - second map key
        value2 - second mapped value
        key3 - third map key
        value3 - third mapped value
        Returns:
        new PMap
      • of

        public static PMap of​(String key1,
                              Object value1,
                              String key2,
                              Object value2,
                              String key3,
                              Object value3,
                              String key4,
                              Object value4)
        Create a PMap with four mappings. Map values that are not Value types will be converted automatically.
        Parameters:
        key1 - first map key
        value1 - first mapped value
        key2 - second map key
        value2 - second mapped value
        key3 - third map key
        value3 - third mapped value
        key4 - fourth map key
        value4 - fourth mapped value
        Returns:
        new PMap
      • of

        public static PMap of​(String key1,
                              Object value1,
                              String key2,
                              Object value2,
                              String key3,
                              Object value3,
                              String key4,
                              Object value4,
                              String key5,
                              Object value5)
        Create a PMap with five mappings. Map values that are not Value types will be converted automatically.
        Parameters:
        key1 - first map key
        value1 - first mapped value
        key2 - second map key
        value2 - second mapped value
        key3 - third map key
        value3 - third mapped value
        key4 - fourth map key
        value4 - fourth mapped value
        key5 - fifth map key
        value5 - fifth mapped value
        Returns:
        new PMap
      • from

        public static Optional<PMap> from​(Value value)
        Cast or convert the provided value into a PMap, wrapped in an Optional. If the value is already a PMap, the Optional will wrap the existing value. If the value is not a PMap and cannot be converted into one, an empty Optional is returned.
        Parameters:
        value - value
        Returns:
        optional PArray
      • merge

        public static PMap merge​(PMap base,
                                 PMap additional,
                                 BinaryOperator<Value> operator)
        Create a new PMap by merging the additional map into the base map, according to the result of the provided operator. The operator will be called for all values in the additional map, even if no mapping exists in the base map. The operator must be able to handle null input. The operator should return the resulting mapped value, or null to remove the mapping. See REPLACE and IF_ABSENT for operators that should cover most common usage.
        Parameters:
        base - base map
        additional - additional map
        operator - operator to compute result value
        Returns:
        new PMap
      • builder

        public static PMap.Builder builder()
        Create a PMap.Builder.
        Returns:
        new PMap.Builder