Module graph

Class Attribute<T>

java.lang.Object
de.grogra.graph.Attribute<T>
All Implemented Interfaces:
Described, KeyDescription, Comparable
Direct Known Subclasses:
BooleanAttribute, ByteAttribute, CharAttribute, DoubleAttribute, FloatAttribute, IntAttribute, LongAttribute, ObjectAttribute, ShortAttribute, VoidAttribute

public abstract class Attribute<T> extends Object implements KeyDescription, Comparable
An Attribute represents an attribute of nodes and edges in a Graph. Attribute values are read and written on objects within the context of a GraphState, the corresponding get- and set-methods are declared in this class, its type-dependent subclasses (IntAttribute, ObjectAttribute, ...), and in GraphState.

Attributes may be derived (see isDerived()), which means that their values are not directly stored in objects, but are computed on the basis of the state of the object, and possibly of neighbouring objects, too. Values of derived attributes cannot be written.

Author:
Ole Kniemeyer
  • Field Details

    • ATTRIBUTE_0

      public static final Attribute[] ATTRIBUTE_0
      An attribute array of length 0.
    • attrType

      protected final Type attrType
    • quantity

      protected final Quantity quantity
  • Method Details

    • forName

      public static final Attribute forName(String name)
      Returns the attribute with the specified name. If an attribute with that name has not yet been registered by initializeName(String), null is returned.
      Parameters:
      name - name of an attribute
      Returns:
      corresponding attribute or null
    • initializeName

      public final Attribute initializeName(String name)
    • initializeI18N

      public final Attribute initializeI18N(I18NBundle bundle, String resourceKey)
    • toArray

      public final Attribute[] toArray()
      Returns an array of length one containing this attribute. The component of the returned array must not be modified.
      Returns:
      an array with this attribute as single component
    • getType

      public final Type getType()
      Returns the type of values of this attribute.
      Specified by:
      getType in interface KeyDescription
      Returns:
      the type of values
    • getKey

      public final String getKey()
      Returns the unique, fully-qualified name of this attribute.
      Specified by:
      getKey in interface KeyDescription
      Returns:
      fully-qualified name
    • getSimpleName

      public final String getSimpleName()
      Returns the simple name of this attribute. Simple names are not necessarily unique.
      Returns:
      this attribute's simple name
    • getQuantity

      public final Quantity getQuantity()
      Returns the physical quantity of this attribute.
      Specified by:
      getQuantity in interface KeyDescription
      Returns:
      quantity of attribute
    • getDescription

      public Object getDescription(String type)
      Description copied from interface: Described
      Returns the description associated with the given type. type has to be one of the predefined constants of this interface, the returned value has to conform to the specification of the used constant.
      Specified by:
      getDescription in interface Described
      Parameters:
      type - the type of description
      Returns:
      the description, or null if no description is available
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • get

      public abstract T get(Object object, boolean asNode, GraphState gs)
      Returns the value of this attribute for the given object in the given graph state. If necessary, the value is wrapped in one of the standard wrapper classes.
      Parameters:
      object - the object
      asNode - true if object is a node, false if object is an edge
      gs - the graph state context
      Returns:
      the value of this attribute for the given object
    • set

      public abstract T set(Object object, boolean asNode, Object value, GraphState gs)
      Sets the value of this attribute for the given object to the given value
      Parameters:
      object - the object
      asNode - true if object is a node, false if object is an edge
      value - the new value of the attribute for the object
      gs - the graph state context
    • find

      public static AttributeAccessor find(AttributeAccessor[] accessors, String name)
      Finds an attribute accessor corresponding to a name in a list of accessors. If the attribute of one of the accessors has a name or a simple name which equals the given name, then this accessor is returned, otherwise null. null-values are allowed within accessors.
      Parameters:
      accessors - the array of accessors
      name - the name to search
      Returns:
      an accessor of the list, corresponding to name, or null
    • isDerived

      public boolean isDerived()
      Determines whether this is a derived attribute or not.
      Returns:
      true iff this is a derived attribute
    • isWritable

      public boolean isWritable(Object object, boolean asNode, GraphState gs)
      Checks whether a value for this attribute can be written to the given object.
      Parameters:
      object - the object
      asNode - true if object is a node, false if object is an edge
      gs - the graph state context
      Returns:
      true iff the attribute is writable for the given object
    • getId

      public final int getId()
      Returns a unique id for this attribute. The ids of derived attributes are negative, the ids of normal attributes are non-negative.
      Returns:
      a unique id
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public final int compareTo(Object o)
      Specified by:
      compareTo in interface Comparable<T>
    • isContained

      public final boolean isContained(Attribute[] b)
      Checks whether this attribute is contained in the sorted array b. The array has to be sorted in ascending order according to the order induced by compareTo(Object).
      Parameters:
      b - a sorted array of attributes
      Returns:
      true iff this attribute is contained in b
    • setAttributeState

      protected final void setAttributeState(GraphState gs, Object info)
    • getAttributeState

      protected final Object getAttributeState(GraphState gs)