Class AttributeType<T>
- java.lang.Object
-
- com.opengamma.strata.product.AttributeType<T>
-
- Type Parameters:
T
- the type of the attribute value
- All Implemented Interfaces:
Named
,Serializable
,Comparable<AttributeType<T>>
public final class AttributeType<T> extends Object implements Named, Comparable<AttributeType<T>>, Serializable
The type that provides meaning to an attribute.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)
andfromStoredForm(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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
DESCRIPTION
public static final AttributeType<String> DESCRIPTION
Key used to access the description.
-
NAME
public static final AttributeType<String> NAME
Key used to access the name.
-
CCP
public static final AttributeType<CcpId> CCP
Key used to access the CCP.
-
-
Method Detail
-
of
public static <T> AttributeType<T> of(String name)
Obtains an instance from the specified name, which should be pre-registered.The name may contain any character, but must not be empty.
- Type Parameters:
T
- the type associated with the info- Parameters:
name
- the name- Returns:
- an instance with the specified name
- Throws:
IllegalArgumentException
- if the instance is not registered
-
registerInstance
public static <T> AttributeType<T> registerInstance(String name, Class<T> type, String... aliases)
Registers an instance for the specified name and type.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.
- Type Parameters:
T
- the type associated with the info- Parameters:
name
- the nametype
- the type of the valuealiases
- the aliases to register under- Returns:
- a type instance with the specified name
-
getName
public String getName()
Gets the name.
-
captureWildcard
public <R> AttributeType<R> captureWildcard()
Captures the wildcard type.This is intended to handle the case where you have
AttributeType<?>
but needAttributeType<T>
. Care must be used, as incorrect use can lead toClassCastException
.- Type Parameters:
R
- the captured type- Returns:
- the normalized form
-
normalized
public AttributeType<T> normalized()
Returns the normalized form of the attribute type.This handles situations where the
AttributeType
instance was created before the constant was registered.- Returns:
- the normalized form
-
toStoredForm
public Object toStoredForm(T value)
Converts the value to the stored form.This method is not for general use. Only implementations of
Attributes
should use it.- Parameters:
value
- the value, may be null- Returns:
- the stored form of the value, may be null
-
fromStoredForm
public T fromStoredForm(Object storedValue)
Converts from the stored form.This method is not for general use. Only implementations of
Attributes
should use it.- Parameters:
storedValue
- the stored value, may be null- Returns:
- the converted value, may be null
-
compareTo
public final int compareTo(AttributeType<T> other)
Compares this type to another.Instances are compared in alphabetical order based on the name.
- Specified by:
compareTo
in interfaceComparable<T>
- Parameters:
other
- the object to compare to- Returns:
- the comparison
-
equals
public final boolean equals(Object obj)
Checks if this type equals another.Instances are compared based on the name.
-
hashCode
public final int hashCode()
Returns a suitable hash code.
-
-