public final class TypedMap
extends java.lang.Object
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 and Description |
---|
TypedMap(play.api.libs.typedmap.TypedMap underlying) |
Modifier and Type | Method and Description |
---|---|
play.api.libs.typedmap.TypedMap |
asScala() |
boolean |
containsKey(TypedKey<?> key)
Check if the map contains a value with the given key.
|
static TypedMap |
create(TypedEntry<?>... entries) |
static TypedMap |
empty() |
<A> A |
get(TypedKey<A> key)
Get a value from the map, throwing an exception if it is not present.
|
<A> java.util.Optional<A> |
getOptional(TypedKey<A> key)
Get a value from the map, returning an empty
Optional if it is not present. |
<A> TypedMap |
put(TypedKey<A> key,
A value)
Update the map with the given key and value, returning a new instance of the map.
|
TypedMap |
putAll(TypedEntry<?>... entries)
Update the map with several entries, returning a new instance of the map.
|
java.lang.String |
toString() |
play.api.libs.typedmap.TypedMap |
underlying()
Deprecated.
As of release 2.6.8. Use
asScala() |
@Deprecated public play.api.libs.typedmap.TypedMap underlying()
asScala()
public play.api.libs.typedmap.TypedMap asScala()
public <A> A get(TypedKey<A> key)
A
- The type of value to retrieve.key
- The key for the value to retrieve.java.util.NoSuchElementException
- If the value isn't present in the map.public <A> java.util.Optional<A> getOptional(TypedKey<A> key)
Optional
if it is not present.A
- The type of value to retrieve.key
- The key for the value to retrieve.Optional
, with the value present if it is in the map.public boolean containsKey(TypedKey<?> key)
key
- The key to check for.public <A> TypedMap put(TypedKey<A> key, A value)
A
- The type of value.key
- The key to set.value
- The value to use.public TypedMap putAll(TypedEntry<?>... entries)
entries
- The new entries to add to the map.public java.lang.String toString()
toString
in class java.lang.Object
public static TypedMap empty()
TypedMap
instance.public static TypedMap create(TypedEntry<?>... entries)
entries
- the list of typed entriesTypedMap
from a list of keys and values.