java.lang.Object
javax.money.AbstractContext
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
AbstractQuery,AmountFormatContext,ConversionContext,CurrencyContext,MonetaryContext,ProviderContext,RoundingContext
public abstract class AbstractContext
extends java.lang.Object
implements java.io.Serializable
Represents a general context of data targeting an item of type
Q. Contexts are used to add arbitrary
data that cannot be be mapped in a standard way to the money API, e.g. use case or customer specific
extensions or specialities.Superclasses of this class must be final, immutable, serializable and thread-safe.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringKEY_PROVIDERKey for storing the target providers to be queried -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractContext(AbstractContextBuilder<?,?> builder)Private constructor, used byAbstractContextBuilder. -
Method Summary
Modifier and Type Method Description booleanequals(java.lang.Object obj)<T> Tget(java.lang.Class<T> type)Access an attribute, hereby using the class name as key.<T> Tget(java.lang.String key, java.lang.Class<T> type)Access an attribute.java.lang.BooleangetBoolean(java.lang.String key)Access a Boolean attribute.java.lang.DoublegetDouble(java.lang.String key)Access a Double attribute.java.lang.FloatgetFloat(java.lang.String key)Access a Float attribute.java.lang.IntegergetInt(java.lang.String key)Access an Integer attribute.java.util.Set<java.lang.String>getKeys(java.lang.Class<?> type)Get the present keys of all entries with a given type, checking hereby if assignable.java.lang.LonggetLong(java.lang.String key)Access a Long attribute.java.lang.StringgetProviderName()Get the provider name of this context.java.lang.StringgetText(java.lang.String key)Access a String attribute.java.lang.Class<?>getType(java.lang.String key)Get the current attribute type.inthashCode()booleanisEmpty()Checks if the current instance has no attributes set.java.lang.StringtoString()
-
Field Details
-
KEY_PROVIDER
protected static final java.lang.String KEY_PROVIDERKey for storing the target providers to be queried- See Also:
- Constant Field Values
-
-
Constructor Details
-
AbstractContext
Private constructor, used byAbstractContextBuilder.- Parameters:
builder- the Builder.
-
-
Method Details
-
getKeys
public java.util.Set<java.lang.String> getKeys(java.lang.Class<?> type)Get the present keys of all entries with a given type, checking hereby if assignable.- Parameters:
type- The attribute type, not null.- Returns:
- all present keys of attributes being assignable to the type, never null.
-
getType
public java.lang.Class<?> getType(java.lang.String key)Get the current attribute type.- Parameters:
key- the entry's key, not null- Returns:
- the current attribute type, or null, if no such attribute exists.
-
get
public <T> T get(java.lang.String key, java.lang.Class<T> type)Access an attribute.- Parameters:
type- the attribute's type, notnullkey- the attribute's key, notnull- Returns:
- the attribute value, or
null.
-
get
public <T> T get(java.lang.Class<T> type)Access an attribute, hereby using the class name as key.- Parameters:
type- the type, notnull- Returns:
- the type attribute value, or
null.
-
getLong
public java.lang.Long getLong(java.lang.String key)Access a Long attribute.- Parameters:
key- the attribute's key, not null.- Returns:
- the value, or null.
-
getFloat
public java.lang.Float getFloat(java.lang.String key)Access a Float attribute.- Parameters:
key- the attribute's key, not null.- Returns:
- the value, or null.
-
getInt
public java.lang.Integer getInt(java.lang.String key)Access an Integer attribute.- Parameters:
key- the attribute's key, not null.- Returns:
- the value, or null.
-
getBoolean
public java.lang.Boolean getBoolean(java.lang.String key)Access a Boolean attribute.- Parameters:
key- the attribute's key, not null.- Returns:
- the value, or null.
-
getDouble
public java.lang.Double getDouble(java.lang.String key)Access a Double attribute.- Parameters:
key- the attribute's key, not null.- Returns:
- the value, or null.
-
getText
public java.lang.String getText(java.lang.String key)Access a String attribute.- Parameters:
key- the attribute's key, not null.- Returns:
- the value, or null.
-
getProviderName
public java.lang.String getProviderName()Get the provider name of this context.- Returns:
- the provider name, or null.
-
isEmpty
public boolean isEmpty()Checks if the current instance has no attributes set. This is often the cases, when used in default cases.- Returns:
- true, if no attributes are set.
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-