Class 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) 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.

    See Also:
    Serialized Form
    • 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 name
        type - the type of the value
        aliases - the aliases to register under
        Returns:
        a type instance with the specified name
      • getName

        public String getName()
        Gets the name.
        Specified by:
        getName in interface Named
        Returns:
        the name
      • captureWildcard

        public <R> AttributeType<R> captureWildcard()
        Captures the wildcard type.

        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.

        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 interface Comparable<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.

        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare to, null returns false
        Returns:
        true if equal
      • hashCode

        public final int hashCode()
        Returns a suitable hash code.
        Overrides:
        hashCode in class Object
        Returns:
        a suitable hash code
      • toString

        public final String toString()
        Returns the name.
        Overrides:
        toString in class Object
        Returns:
        the string form, not empty