public class Context extends HashMap<String,Object> implements Cloneable
Map
which can give typed elements and can fail
gracefully when elements don't exist.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Constructor and Description |
---|
Context()
Default constructor to make an empty
Context . |
Context(boolean failfast)
Construct an empty
Context . |
Context(Object... nameval)
A conveniance function where nameval.length % 2 is assumed to == 0 and
nameval contains pairs of "key" : value instances
|
Modifier and Type | Method and Description |
---|---|
Context |
clone() |
Context |
combine(Context that,
String thisprefix,
String thatprefix)
|
<T> T |
getTyped(String key)
Get the object from the context with the given key and coerce the type.
|
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
equals, hashCode, toString
public Context()
Context
. The Context is
configured to return null
from getTyped(String)
if
there is a casting issue or the object doesn't exist.public Context(Object... nameval)
nameval
- public Context(boolean failfast)
Context
. The Context can optionally be
configured to either return null
from
getTyped(String)
or throw a RuntimeException
if there is
a casting issue or the object doesn't exist.failfast
- forces the getTyped to throw a runtime exception if set and
the object does not exist or is not the correct typepublic <T> T getTyped(String key)
key
- the keypublic Context combine(Context that, String thisprefix, String thatprefix)
Context
with another context by modifying any shared
keys of both contexts to be prefixed with the given prefixes and then
copying all the data from the given Context
into this one.
If both prefixes are the same then the data being copied from the other
context will have precedence. The prefixes can be null
.
that
- the context to combine with thisthisprefix
- the prefix for keys in this contextthatprefix
- the prefix for keys in the other context