Class Attribute<T>

  • Type Parameters:
    T - the type of the named attribute
    All Implemented Interfaces:
    Named

    public class Attribute<T>
    extends java.lang.Object
    implements Named
    An attribute is a named entity with a type. It is used in conjunction with a AttributeContainer to provide a type safe container for attributes. This class isn't intended to store the value of an attribute, but only represent the identity of the attribute. It means that an attribute must be immutable and can potentially be pooled. Attributes can be created using the factory method.
    Since:
    3.3
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.gradle.api.Named

        Named.Namer
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      java.lang.String getName()
      Returns the name of the attribute.
      java.lang.Class<T> getType()
      Returns the type of this attribute.
      int hashCode()  
      static <T> Attribute<T> of​(java.lang.Class<T> type)
      Creates a new attribute of the given type, inferring the name of the attribute from the simple type name.
      static <T> Attribute<T> of​(java.lang.String name, java.lang.Class<T> type)
      Creates a new attribute of the given name with the given type.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • of

        public static <T> Attribute<T> of​(java.lang.String name,
                                          java.lang.Class<T> type)
        Creates a new attribute of the given name with the given type. There's no guarantee that subsequent calls to this method with the same attributes would either return the same instance or different instances of Attribute, so consumers are required to compare the attributes with the equals(Object) method.
        Type Parameters:
        T - the type of the attribute
        Parameters:
        name - the name of the attribute
        type - the class of the attribute
        Returns:
        an attribute with the given name and type
      • of

        public static <T> Attribute<T> of​(java.lang.Class<T> type)
        Creates a new attribute of the given type, inferring the name of the attribute from the simple type name. This method is useful when there's supposedly only one attribute of a specific type in a container, so there's no need to distinguish by name (but the returned type doesn't enforce it_. There's no guarantee that subsequent calls to this method with the same attributes would either return the same instance or different instances of Attribute, so consumers are required to compare the attributes with the equals(Object) method.
        Type Parameters:
        T - the type of the attribute
        Parameters:
        type - the class of the attribute
        Returns:
        an attribute with the given name and type
      • getName

        public java.lang.String getName()
        Returns the name of the attribute.
        Specified by:
        getName in interface Named
        Returns:
        the name of the attribute.
      • getType

        public java.lang.Class<T> getType()
        Returns the type of this attribute.
        Returns:
        the type of this attribute.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object