-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA PMap builder.static final classstatic classAn abstract superclass for values that are backed solely by a PMap.Nested classes/interfaces inherited from class org.praxislive.core.Value
Value.Type<T extends Value> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PMapAn empty PMap.static final BinaryOperator<Value> An operator for use withmerge(org.praxislive.core.types.PMap, org.praxislive.core.types.PMap, java.util.function.BinaryOperator)that only adds mappings where the key is not present in the base map.static final BinaryOperator<Value> An operator for use withmerge(org.praxislive.core.types.PMap, org.praxislive.core.types.PMap, java.util.function.BinaryOperator)that will replace mapped values in the base map, unless the new value is empty in which case the mapping is removed.static final StringValue type name. -
Method Summary
Modifier and TypeMethodDescriptionasMap()An unmodifiableOrderedMapview of this PMap.<T> OrderedMap<String, T> Access an unmodifiableOrderedMapview of this PMap as a map of the provided value type.static PMap.Builderbuilder()Create a PMap.Builder.static PMap.EntryCreate aPMap.Entryfor creating a PMap.booleanValues must override the default equals method.booleanequivalent(Value arg) Indicates whether some other Value is equivalent to this one.Cast or convert the provided value into a PMap, wrapped in an Optional.Get the value for the given key, or null if the key does not exist.booleangetBoolean(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.doubleGet 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.intGet 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.Get a String value from the map, returning a default value if the key is not mapped.inthashCode()Values must override the default hashcode method.booleanisEmpty()Check whether this Value is an empty value and has a zero length string representation.keys()List of map keys.static PMapmerge(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.static PMapCreate a PMap with one mapping.static PMapCreate a PMap with two mappings.static PMapCreate a PMap with three mappings.static PMapof(String key1, Object value1, String key2, Object value2, String key3, Object value3, String key4, Object value4) Create a PMap with four mappings.static PMapof(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.static PMapofEntries(PMap.Entry... entries) Create a PMap of the provided mappings.static PMapCreate a PMap from the providedMap.static PMapParse the given text into a PMap.intsize()Size of the map.toString()Values must override the default method to return a string representation that is immutable.
-
Field Details
-
TYPE_NAME
Value type name.- See Also:
-
EMPTY
An empty PMap. -
IF_ABSENT
An operator for use withmerge(org.praxislive.core.types.PMap, org.praxislive.core.types.PMap, java.util.function.BinaryOperator)that only adds mappings where the key is not present in the base map. -
REPLACE
An operator for use withmerge(org.praxislive.core.types.PMap, org.praxislive.core.types.PMap, java.util.function.BinaryOperator)that will replace mapped values in the base map, unless the new value is empty in which case the mapping is removed.
-
-
Method Details
-
get
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
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 keydef- default if unmapped or invalid- Returns:
- value or default
-
getInt
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 keydef- default if unmapped or invalid- Returns:
- value or default
-
getDouble
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 keydef- default if unmapped or invalid- Returns:
- value or default
-
getString
Get a String value from the map, returning a default value if the key is not mapped.- Parameters:
key- map keydef- 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
List of map keys. This is returned as a List as the keys are ordered.- Returns:
- map keys
-
asMap
An unmodifiableOrderedMapview of this PMap.- Returns:
- map view
-
asMapOf
Access an unmodifiableOrderedMapview of this PMap as a map of the provided value type.If the provided type is
Valuethen this method acts the same as callingasMap().If the provided type is a Value subclass and all values in the map returned by
asMap()are of this type, then the map is cast and returned.If the provided type is a Value subclass or any other type supported by
ValueMapperthen a new map will be returned with the values converted to the required type.This method throws an
IllegalArgumentExceptionif no value mapper exists for the provided type, of if not all map values can be converted to the provided type.- Type Parameters:
T- value type- Parameters:
type- class of the value type- Returns:
- ordered map view of the provided value type
- Throws:
IllegalArgumentException- if there is no mapper for the provided type, or if all values cannot be converted to the provided type
-
toString
Description copied from class:ValueValues must override the default method to return a string representation that is immutable. -
isEmpty
public boolean isEmpty()Description copied from class:ValueCheck 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. -
equivalent
Description copied from class:ValueIndicates whether some other Value is equivalent to this one. UnlikeValue.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:
equivalentin classValue- Parameters:
arg- value to test for equivalence- Returns:
- true if value is equivalent to this
-
hashCode
public int hashCode()Description copied from class:ValueValues must override the default hashcode method. -
equals
Description copied from class:ValueValues must override the default equals method. This method should only returntrueif 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 thatthis.equals(that) == this.toString().equals(that.toString()) -
of
Create a PMap with one mapping. Map values that are notValuetypes will be converted automatically.- Parameters:
key- map keyvalue- mapped value- Returns:
- new PMap
-
of
Create a PMap with two mappings. Map values that are notValuetypes will be converted automatically.- Parameters:
key1- first map keyvalue1- first mapped valuekey2- second map keyvalue2- 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 notValuetypes will be converted automatically.- Parameters:
key1- first map keyvalue1- first mapped valuekey2- second map keyvalue2- second mapped valuekey3- third map keyvalue3- 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 notValuetypes will be converted automatically.- Parameters:
key1- first map keyvalue1- first mapped valuekey2- second map keyvalue2- second mapped valuekey3- third map keyvalue3- third mapped valuekey4- fourth map keyvalue4- 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 notValuetypes will be converted automatically.- Parameters:
key1- first map keyvalue1- first mapped valuekey2- second map keyvalue2- second mapped valuekey3- third map keyvalue3- third mapped valuekey4- fourth map keyvalue4- fourth mapped valuekey5- fifth map keyvalue5- fifth mapped value- Returns:
- new PMap
-
ofEntries
Create a PMap of the provided mappings. Useentry(java.lang.String, java.lang.Object)to create entries.- Parameters:
entries- map entries- Returns:
- new PMap
-
entry
Create aPMap.Entryfor creating a PMap. Values that are notValuetypes will be converted automatically.- Parameters:
key- map keyvalue- map value- Returns:
- map entry
-
ofMap
Create a PMap from the providedMap. The order of keys in the PMap will be based on the iteration order of the map.If the provided map is an
OrderedMapthen no copy of the map will be made and the map returned byasMap()will be the map passed in to this method.- Parameters:
map- map to copy- Returns:
- new PMap
-
parse
Parse the given text into a PMap.- Parameters:
text- text to parse- Returns:
- parsed PArray
- Throws:
ValueFormatException
-
from
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 PMap
-
merge
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. SeeREPLACEandIF_ABSENTfor operators that should cover most common usage.- Parameters:
base- base mapadditional- additional mapoperator- operator to compute result value- Returns:
- new PMap
-
builder
Create a PMap.Builder.- Returns:
- new PMap.Builder
-