Package play.libs.typedmap
Class TypedMap
java.lang.Object
play.libs.typedmap.TypedMap
A TypedMap is an immutable map containing typed values. Each entry is associated with a
TypedKey that can be used to look up the value. A TypedKey also defines the type of
the value, e.g. a TypedKey<String> would be associated with a String
value.
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 -
Method Summary
Modifier and TypeMethodDescriptionplay.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 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> TypedMapUpdate the map with the given key and value, returning a new instance of the map.putAll(List<TypedEntry<?>> entries) Update the map with several entries, returning a new instance of the map.putAll(TypedEntry<?> e1) Update the map with one entry, returning a new instance of the map.putAll(TypedEntry<?>... entries) Update the map with several entries, returning a new instance of the map.putAll(TypedEntry<?> e1, TypedEntry<?> e2) Update the map with two entries, returning a new instance of the map.putAll(TypedEntry<?> e1, TypedEntry<?> e2, TypedEntry<?> e3) Update the map with three entries, returning a new instance of the map.Removes a key from the map, returning a new instance of the map.Removes keys from the map, returning a new instance of the map.Removes two keys from the map, returning a new instance of the map.Removes three keys from the map, returning a new instance of the map.toString()
-
Constructor Details
-
TypedMap
public TypedMap(play.api.libs.typedmap.TypedMap underlying)
-
-
Method Details
-
asScala
public play.api.libs.typedmap.TypedMap asScala()- Returns:
- the underlying Scala TypedMap which this instance wraps.
-
get
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
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
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
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
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
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
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
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
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
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
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
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
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.
-
toString
-
empty
- Returns:
- the empty
TypedMapinstance.
-
create
- Parameters:
e1- typed entry- Returns:
- a newly built
TypedMapfrom a entry of key and value.
-
create
- Parameters:
e1- first typed entrye2- second typed entry- Returns:
- a newly built
TypedMapfrom a two entries of keys and values.
-
create
- Parameters:
e1- first typed entrye2- second typed entrye3- third typed entry- Returns:
- a newly built
TypedMapfrom a three entries of keys and values.
-
create
- Parameters:
entries- the list of typed entries- Returns:
- a newly built
TypedMapfrom a list of keys and values.
-