Package play.libs.typedmap
Class TypedMap
- Object
-
- play.libs.typedmap.TypedMap
-
public final class TypedMap extends Object
A TypedMap is an immutable map containing typed values. Each entry is associated with aTypedKeythat can be used to look up the value. ATypedKeyalso defines the type of the value, e.g. aTypedKey<String>would be associated with aStringvalue.Instances of this class are created with the
empty()method.The elements inside TypedMaps cannot be enumerated. This is a decision designed to enforce modularity. It's not possible to accidentally or intentionally access a value in a TypedMap without holding the corresponding
TypedKey.
-
-
Constructor Summary
Constructors Constructor Description TypedMap(play.api.libs.typedmap.TypedMap underlying)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description play.api.libs.typedmap.TypedMapasScala()booleancontainsKey(TypedKey<?> key)Check if the map contains a value with the given key.static TypedMapcreate(TypedEntry<?> e1)static TypedMapcreate(TypedEntry<?>... entries)static TypedMapcreate(TypedEntry<?> e1, TypedEntry<?> e2)static TypedMapcreate(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3)static TypedMapempty()<A> Aget(TypedKey<A> key)Get a value from the map, throwing an exception if it is not present.<A> Optional<A>getOptional(TypedKey<A> key)Get a value from the map, returning an emptyOptionalif it is not present.<A> TypedMapput(TypedKey<A> key, A value)Update the map with the given key and value, returning a new instance of the map.TypedMapputAll(List<TypedEntry<?>> entries)Update the map with several entries, returning a new instance of the map.TypedMapputAll(TypedEntry<?> e1)Update the map with one entry, returning a new instance of the map.TypedMapputAll(TypedEntry<?>... entries)Update the map with several entries, returning a new instance of the map.TypedMapputAll(TypedEntry<?> e1, TypedEntry<?> e2)Update the map with two entries, returning a new instance of the map.TypedMapputAll(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3)Update the map with three entries, returning a new instance of the map.TypedMapremove(TypedKey<?> k1)Removes a key from the map, returning a new instance of the map.TypedMapremove(TypedKey<?>... keys)Removes keys from the map, returning a new instance of the map.TypedMapremove(TypedKey<?> k1, TypedKey<?> k2)Removes two keys from the map, returning a new instance of the map.TypedMapremove(TypedKey<?> k1, TypedKey<?> k2, TypedKey<?> k3)Removes three keys from the map, returning a new instance of the map.StringtoString()
-
-
-
Method Detail
-
asScala
public play.api.libs.typedmap.TypedMap asScala()
- Returns:
- the underlying Scala TypedMap which this instance wraps.
-
get
public <A> A get(TypedKey<A> key)
Get a value from the map, throwing an exception if it is not present.- Type Parameters:
A- The type of value to retrieve.- Parameters:
key- The key for the value to retrieve.- Returns:
- The value, if it is present in the map.
- Throws:
NoSuchElementException- If the value isn't present in the map.
-
getOptional
public <A> Optional<A> getOptional(TypedKey<A> key)
Get a value from the map, returning an emptyOptionalif it is not present.- Type Parameters:
A- The type of value to retrieve.- Parameters:
key- The key for the value to retrieve.- Returns:
- An
Optional, with the value present if it is in the map.
-
containsKey
public boolean containsKey(TypedKey<?> key)
Check if the map contains a value with the given key.- Parameters:
key- The key to check for.- Returns:
- True if the value is present, false otherwise.
-
put
public <A> TypedMap put(TypedKey<A> key, A value)
Update the map with the given key and value, returning a new instance of the map.- Type Parameters:
A- The type of value.- Parameters:
key- The key to set.value- The value to use.- Returns:
- A new instance of the map with the new entry added.
-
putAll
public TypedMap putAll(TypedEntry<?> e1)
Update the map with one entry, returning a new instance of the map.- Parameters:
e1- The new entry to add to the map.- Returns:
- A new instance of the map with the new entry added.
-
putAll
public TypedMap putAll(TypedEntry<?> e1, TypedEntry<?> e2)
Update the map with two entries, returning a new instance of the map.- Parameters:
e1- The first new entry to add to the map.e2- The second new entry to add to the map.- Returns:
- A new instance of the map with the new entries added.
-
putAll
public TypedMap putAll(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3)
Update the map with three entries, returning a new instance of the map.- Parameters:
e1- The first new entry to add to the map.e2- The second new entry to add to the map.e3- The third new entry to add to the map.- Returns:
- A new instance of the map with the new entries added.
-
putAll
public TypedMap putAll(TypedEntry<?>... entries)
Update the map with several entries, returning a new instance of the map.- Parameters:
entries- The new entries to add to the map.- Returns:
- A new instance of the map with the new entries added.
-
putAll
public TypedMap putAll(List<TypedEntry<?>> entries)
Update the map with several entries, returning a new instance of the map.- Parameters:
entries- The new entries to add to the map.- Returns:
- A new instance of the map with the new entries added.
-
remove
public TypedMap remove(TypedKey<?> k1)
Removes a key from the map, returning a new instance of the map.- Parameters:
k1- The key to remove.- Returns:
- A new instance of the map with the entry removed.
-
remove
public TypedMap remove(TypedKey<?> k1, TypedKey<?> k2)
Removes two keys from the map, returning a new instance of the map.- Parameters:
k1- The first key to remove.k2- The second key to remove.- Returns:
- A new instance of the map with the entries removed.
-
remove
public TypedMap remove(TypedKey<?> k1, TypedKey<?> k2, TypedKey<?> k3)
Removes three keys from the map, returning a new instance of the map.- Parameters:
k1- The first key to remove.k2- The second key to remove.k3- The third key to remove.- Returns:
- A new instance of the map with the entries removed.
-
remove
public TypedMap remove(TypedKey<?>... keys)
Removes keys from the map, returning a new instance of the map.- Parameters:
keys- The keys to remove.- Returns:
- A new instance of the map with the entries removed.
-
empty
public static TypedMap empty()
- Returns:
- the empty
TypedMapinstance.
-
create
public static TypedMap create(TypedEntry<?> e1)
- Parameters:
e1- typed entry- Returns:
- a newly built
TypedMapfrom a entry of key and value.
-
create
public static TypedMap create(TypedEntry<?> e1, TypedEntry<?> e2)
- Parameters:
e1- first typed entrye2- second typed entry- Returns:
- a newly built
TypedMapfrom a two entries of keys and values.
-
create
public static TypedMap create(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3)
- Parameters:
e1- first typed entrye2- second typed entrye3- third typed entry- Returns:
- a newly built
TypedMapfrom a three entries of keys and values.
-
create
public static TypedMap create(TypedEntry<?>... entries)
- Parameters:
entries- the list of typed entries- Returns:
- a newly built
TypedMapfrom a list of keys and values.
-
-