de.grogra.graph
Class Attribute<T>

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

public abstract class Attribute<T>
extends java.lang.Object
implements KeyDescription, java.lang.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 Summary
static Attribute[] ATTRIBUTE_0
          An attribute array of length 0.
protected  Type attrType
           
protected  Quantity quantity
           
 
Fields inherited from interface de.grogra.util.Described
ACCELERATOR_KEY, ICON, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, TITLE
 
Method Summary
 int compareTo(java.lang.Object o)
           
static AttributeAccessor find(AttributeAccessor[] accessors, java.lang.String name)
          Finds an attribute accessor corresponding to a name in a list of accessors.
static Attribute forName(java.lang.String name)
          Returns the attribute with the specified name.
abstract  T get(java.lang.Object object, boolean asNode, GraphState gs)
          Returns the value of this attribute for the given object in the given graph state.
protected  java.lang.Object getAttributeState(GraphState gs)
           
 java.lang.Object getDescription(java.lang.String type)
          Returns the description associated with the given type.
 int getId()
          Returns a unique id for this attribute.
 java.lang.String getKey()
          Returns the unique, fully-qualified name of this attribute.
 Quantity getQuantity()
          Returns the physical quantity of this attribute.
 java.lang.String getSimpleName()
          Returns the simple name of this attribute.
 Type getType()
          Returns the type of values of this attribute.
 int hashCode()
           
 Attribute initializeI18N(I18NBundle bundle, java.lang.String resourceKey)
           
 Attribute initializeName(java.lang.String name)
           
 boolean isContained(Attribute[] b)
          Checks whether this attribute is contained in the sorted array b.
 boolean isDerived()
          Determines whether this is a derived attribute or not.
 boolean isWritable(java.lang.Object object, boolean asNode, GraphState gs)
          Checks whether a value for this attribute can be written to the given object.
abstract  T set(java.lang.Object object, boolean asNode, java.lang.Object value, GraphState gs)
          Sets the value of this attribute for the given object to the given value
protected  void setAttributeState(GraphState gs, java.lang.Object info)
           
 Attribute[] toArray()
          Returns an array of length one containing this attribute.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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 Detail

compareTo

public final int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable

find

public static AttributeAccessor find(AttributeAccessor[] accessors,
                                     java.lang.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

forName

public static final Attribute forName(java.lang.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

get

public abstract T get(java.lang.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

getAttributeState

protected final java.lang.Object getAttributeState(GraphState gs)

getDescription

public java.lang.Object getDescription(java.lang.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

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

getKey

public final java.lang.String getKey()
Returns the unique, fully-qualified name of this attribute.

Specified by:
getKey in interface KeyDescription
Returns:
fully-qualified name

getQuantity

public final Quantity getQuantity()
Returns the physical quantity of this attribute.

Specified by:
getQuantity in interface KeyDescription
Returns:
quantity of attribute

getSimpleName

public final java.lang.String getSimpleName()
Returns the simple name of this attribute. Simple names are not necessarily unique.

Returns:
this attribute's simple name

getType

public final Type getType()
Returns the type of values of this attribute.

Specified by:
getType in interface KeyDescription
Returns:
the type of values

hashCode

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

initializeI18N

public final Attribute initializeI18N(I18NBundle bundle,
                                      java.lang.String resourceKey)

initializeName

public final Attribute initializeName(java.lang.String name)

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

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(java.lang.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

set

public abstract T set(java.lang.Object object,
                      boolean asNode,
                      java.lang.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

setAttributeState

protected final void setAttributeState(GraphState gs,
                                       java.lang.Object info)

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

toString

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