T - the type of the attribute valuepublic final class AttributeType<T> extends Object implements Named, Comparable<AttributeType<T>>, Serializable
Attributes provide the ability to associate arbitrary information with the trade model in a key-value map. For example, it might be used to provide information about the trading platform.
Applications that wish to use attributes should declare a static constant declaring the
AttributeType instance, the type parameter and a lowerCamelCase name. For example:
public static final AttributeType<String> DEALER = AttributeType.registerInstance("dealer", DealerId.class);
The purpose of registering the type is to enable toStoredForm(T) and fromStoredForm(java.lang.Object)}.
If the type can be converted using Joda-Convert's basic converter, then the data will be stored as strings.
This allows the sender and receiver of a message to use a different Java type for the value.
| Modifier and Type | Field and Description |
|---|---|
static AttributeType<BuySell> |
BUY_SELL
Key used to indicate logical Buy/Sell.
|
static AttributeType<CcpId> |
CCP
Key used to access the CCP.
|
static AttributeType<String> |
DESCRIPTION
Key used to access the description.
|
static AttributeType<String> |
NAME
Key used to access the name.
|
| Modifier and Type | Method and Description |
|---|---|
<R> AttributeType<R> |
captureWildcard()
Captures the wildcard type.
|
int |
compareTo(AttributeType<T> other)
Compares this type to another.
|
boolean |
equals(Object obj)
Checks if this type equals another.
|
T |
fromStoredForm(Object storedValue)
Converts from the stored form.
|
String |
getName()
Gets the name.
|
int |
hashCode()
Returns a suitable hash code.
|
AttributeType<T> |
normalized()
Returns the normalized form of the attribute type.
|
static <T> AttributeType<T> |
of(String name)
Obtains an instance from the specified name, which should be pre-registered.
|
static <T> AttributeType<T> |
registerInstance(String name,
Class<T> type,
String... aliases)
Registers an instance for the specified name and type.
|
Object |
toStoredForm(T value)
Converts the value to the stored form.
|
String |
toString()
Returns the name.
|
public static final AttributeType<String> DESCRIPTION
public static final AttributeType<String> NAME
public static final AttributeType<CcpId> CCP
public static final AttributeType<BuySell> BUY_SELL
public static <T> AttributeType<T> of(String name)
The name may contain any character, but must not be empty.
T - the type associated with the infoname - the nameIllegalArgumentException - if the instance is not registeredpublic static <T> AttributeType<T> registerInstance(String name, Class<T> type, String... aliases)
The name may contain any character, but must not be empty.
Aliases can be specified if desired. This is intended to handle the situation where an attribute type is renamed. The old name is the alias, whereas the new name is the main name.
T - the type associated with the infoname - the nametype - the type of the valuealiases - the aliases to register underpublic String getName()
public <R> AttributeType<R> captureWildcard()
This is intended to handle the case where you have AttributeType<?> but need AttributeType<T>.
Care must be used, as incorrect use can lead to ClassCastException.
R - the captured typepublic AttributeType<T> normalized()
This handles situations where the AttributeType instance was created before
the constant was registered.
public Object toStoredForm(T value)
This method is not for general use. Only implementations of Attributes should use it.
value - the value, may be nullpublic T fromStoredForm(Object storedValue)
This method is not for general use. Only implementations of Attributes should use it.
storedValue - the stored value, may be nullpublic final int compareTo(AttributeType<T> other)
Instances are compared in alphabetical order based on the name.
compareTo in interface Comparable<AttributeType<T>>other - the object to compare topublic final boolean equals(Object obj)
Instances are compared based on the name.
public final int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.