Class SimpleAttributes

  • All Implemented Interfaces:
    Attributes, Serializable, org.joda.beans.Bean, org.joda.beans.ImmutableBean

    public final class SimpleAttributes
    extends Object
    implements Attributes, org.joda.beans.ImmutableBean, Serializable
    A simple implementation of attributes.

    Additional attributes can be associated with a model object. This is the simplest possible implementation.

    See Also:
    Serialized Form
    • Method Detail

      • of

        public static <T> SimpleAttributes of​(AttributeType<T> type,
                                              T value)
        Obtains an instance with a single attribute.

        The withAttribute(AttributeType, Object) method can be used on the instance to add more attributes.

        Type Parameters:
        T - the type of the attribute value
        Parameters:
        type - the type providing meaning to the value
        value - the value
        Returns:
        the instance
      • from

        public static SimpleAttributes from​(Attributes other)
        Obtains an instance from another instance, copying the attributes.

        This can be used to ensure that an instance of Attributes contains no state apart from attributes.

        Parameters:
        other - the attributes to copy from
        Returns:
        the instance
      • findAttribute

        public <T> Optional<T> findAttribute​(AttributeType<T> type)
        Description copied from interface: Attributes
        Finds the attribute associated with the specified type.

        This method obtains the specified attribute. This allows an attribute to be obtained if available.

        If the attribute is not found, optional empty is returned.

        Specified by:
        findAttribute in interface Attributes
        Type Parameters:
        T - the type of the result
        Parameters:
        type - the type to find
        Returns:
        the attribute value
      • withAttribute

        public <T> SimpleAttributes withAttribute​(AttributeType<T> type,
                                                  T value)
        Description copied from interface: Attributes
        Returns a copy of this instance with the attribute added.

        This returns a new instance with the specified attribute added. The attribute is added using Map.put(type, value) semantics.

        Specified by:
        withAttribute in interface Attributes
        Type Parameters:
        T - the type of the attribute value
        Parameters:
        type - the type providing meaning to the value
        value - the value
        Returns:
        a new instance based on this one with the attribute added
      • withAttributes

        public SimpleAttributes withAttributes​(Attributes other)
        Description copied from interface: Attributes
        Returns a copy of this instance with the attributes added.

        This returns a new instance with the specified attributes added. The attributes are added using Map.putAll(type, value) semantics.

        Specified by:
        withAttributes in interface Attributes
        Parameters:
        other - the other instance to copy from
        Returns:
        an instance based on this one with the attributes from the other instance
      • meta

        public static org.joda.beans.TypedMetaBean<SimpleAttributes> meta()
        The meta-bean for SimpleAttributes.
        Returns:
        the meta-bean, not null
      • metaBean

        public org.joda.beans.TypedMetaBean<SimpleAttributes> metaBean()
        Specified by:
        metaBean in interface org.joda.beans.Bean
      • getAttributes

        public ImmutableMap<AttributeType<?>,​Object> getAttributes()
        Gets the attributes.

        Attributes provide the ability to associate arbitrary information in a key-value map.

        Returns:
        the value of the property, not null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object