public abstract class AbstractContext
extends java.lang.Object
implements java.io.Serializable
Instances of this class should be immutable and thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractContext.AbstractBuilder<B extends AbstractContext.AbstractBuilder<B>>
Builder class to create
AbstractContext instances. |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Object,java.lang.Object>> |
attributes
Map with the attributes of this context.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractContext(AbstractContext.AbstractBuilder builder)
Private constructor, used by
AbstractContext.AbstractBuilder . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
<T> T |
getAttribute(java.lang.Class<T> type)
Access an attribute, hereby using the class name as key.
|
<T> T |
getAttribute(java.lang.Class<T> type,
T defaultValue)
Access a single attribute, also providing a default value.
|
java.util.Set<java.lang.Class<?>> |
getAttributeTypes()
Access the types of the attributes of this
MonetaryContext . |
<T> T |
getNamedAttribute(java.lang.Class<T> type,
java.lang.Object key)
Access an attribute.
|
<T> T |
getNamedAttribute(java.lang.Class<T> type,
java.lang.Object key,
T defaultValue)
Access an attribute.
|
int |
hashCode() |
protected <T> T |
set(T value)
Sets an attribute, using
attribute.getClass() as attribute
type and attribute.getClass().getName() as attribute
name. |
protected <T> T |
set(T attribute,
java.lang.Object key,
java.lang.Class<? extends T> type)
Set a value, use this method hereby only for initialization to keep
immutable semantics.
|
java.lang.String |
toString() |
protected final java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Object,java.lang.Object>> attributes
protected AbstractContext(AbstractContext.AbstractBuilder builder)
AbstractContext.AbstractBuilder
.builder
- the Builder.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public <T> T getAttribute(java.lang.Class<T> type)
type
- the attribute's type, not null
null
.public <T> T getAttribute(java.lang.Class<T> type, T defaultValue)
type
- the attribute's type, not null
.defaultValue
- the default value, can also be null
.defaultValue
passed, if no
such attribute is present.public java.util.Set<java.lang.Class<?>> getAttributeTypes()
MonetaryContext
.MonetaryContext
,
never null
.public <T> T getNamedAttribute(java.lang.Class<T> type, java.lang.Object key)
type
- the attribute's type, not null
key
- the attribute's key, not null
null
.public <T> T getNamedAttribute(java.lang.Class<T> type, java.lang.Object key, T defaultValue)
type
- the attribute's type, not null
key
- the attribute's key, not null
null
.public int hashCode()
hashCode
in class java.lang.Object
protected final <T> T set(T value)
attribute.getClass()
as attribute
type and attribute.getClass().getName()
as attribute
name.value
- the attribute valueprotected final <T> T set(T attribute, java.lang.Object key, java.lang.Class<? extends T> type)
attribute
- the attributekey
- the keytype
- THE typepublic java.lang.String toString()
toString
in class java.lang.Object