Interface Attributes

    • Method Detail

      • of

        static <T> Attributes 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
      • getAttributeTypes

        default ImmutableSet<AttributeType<?>> getAttributeTypes()
        Gets the attribute types that are available.

        See AttributeType.captureWildcard() for a way to capture the wildcard type.

        The default implementation returns an empty set (backwards compatibility prevents an abstract method for now).

        Returns:
        the attribute types
      • getAttribute

        default <T> T getAttribute​(AttributeType<T> type)
        Gets 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, an exception is thrown.

        Type Parameters:
        T - the type of the attribute value
        Parameters:
        type - the type to find
        Returns:
        the attribute value
        Throws:
        IllegalArgumentException - if the attribute is not found
      • containsAttribute

        default <T> boolean containsAttribute​(AttributeType<T> type)
        Determines if an attribute associated with the specified type is present.
        Type Parameters:
        T - the type of the attribute value
        Parameters:
        type - the type to find
        Returns:
        true if a matching attribute is present
      • containsAttribute

        default <T> boolean containsAttribute​(AttributeType<T> type,
                                              T attributeValue)
        Determines if an attribute associated with the specified type is present and its value is equal to the supplied value.
        Type Parameters:
        T - the type of the attribute value
        Parameters:
        type - the type to find
        attributeValue - the value to match against
        Returns:
        true if a matching attribute is present
      • findAttribute

        <T> Optional<T> findAttribute​(AttributeType<T> type)
        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.

        Type Parameters:
        T - the type of the result
        Parameters:
        type - the type to find
        Returns:
        the attribute value
      • withAttribute

        <T> Attributes withAttribute​(AttributeType<T> type,
                                     T value)
        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.

        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

        default Attributes withAttributes​(Attributes other)
        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.

        Parameters:
        other - the other instance to copy from
        Returns:
        an instance based on this one with the attributes from the other instance