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
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
FieldsModifier and TypeFieldDescriptionstatic final Attribute[]
An attribute array of length 0.protected final Type
protected final Quantity
Fields inherited from interface de.grogra.util.Described
ACCELERATOR_KEY, ICON, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, TITLE
-
Method Summary
Modifier and TypeMethodDescriptionfinal int
static AttributeAccessor
find
(AttributeAccessor[] accessors, String name) Finds an attribute accessor corresponding to aname
in a list ofaccessors
.static final Attribute
Returns the attribute with the specifiedname
.abstract T
get
(Object object, boolean asNode, GraphState gs) Returns the value of this attribute for the given object in the given graph state.protected final Object
getDescription
(String type) Returns the description associated with the giventype
.final int
getId()
Returns a unique id for this attribute.final String
getKey()
Returns the unique, fully-qualified name of this attribute.final Quantity
Returns the physical quantity of this attribute.final String
Returns the simple name of this attribute.final Type
getType()
Returns the type of values of this attribute.final int
hashCode()
final Attribute
initializeI18N
(I18NBundle bundle, String resourceKey) final Attribute
initializeName
(String name) final boolean
isContained
(Attribute[] b) Checks whether this attribute is contained in the sorted arrayb
.boolean
Determines whether this is a derived attribute or not.boolean
isWritable
(Object object, boolean asNode, GraphState gs) Checks whether a value for this attribute can be written to the given object.abstract T
set
(Object object, boolean asNode, Object value, GraphState gs) Sets the value of this attribute for the givenobject
to the givenvalue
protected final void
setAttributeState
(GraphState gs, Object info) final Attribute[]
toArray()
Returns an array of length one containing this attribute.toString()
-
Field Details
-
ATTRIBUTE_0
An attribute array of length 0. -
attrType
-
quantity
-
-
Method Details
-
forName
Returns the attribute with the specifiedname
. If an attribute with that name has not yet been registered byinitializeName(String)
,null
is returned.- Parameters:
name
- name of an attribute- Returns:
- corresponding attribute or
null
-
initializeName
-
initializeI18N
-
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
Returns the type of values of this attribute.- Specified by:
getType
in interfaceKeyDescription
- Returns:
- the type of values
-
getKey
Returns the unique, fully-qualified name of this attribute.- Specified by:
getKey
in interfaceKeyDescription
- Returns:
- fully-qualified name
-
getSimpleName
Returns the simple name of this attribute. Simple names are not necessarily unique.- Returns:
- this attribute's simple name
-
getQuantity
Returns the physical quantity of this attribute.- Specified by:
getQuantity
in interfaceKeyDescription
- Returns:
- quantity of attribute
-
getDescription
Description copied from interface:Described
Returns the description associated with the giventype
.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 interfaceDescribed
- Parameters:
type
- the type of description- Returns:
- the description, or
null
if no description is available
-
toString
-
get
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 objectasNode
-true
ifobject
is a node,false
ifobject
is an edgegs
- the graph state context- Returns:
- the value of this attribute for the given object
-
set
Sets the value of this attribute for the givenobject
to the givenvalue
- Parameters:
object
- the objectasNode
-true
ifobject
is a node,false
ifobject
is an edgevalue
- the new value of the attribute for the objectgs
- the graph state context
-
find
Finds an attribute accessor corresponding to aname
in a list ofaccessors
. If the attribute of one of theaccessors
has a name or a simple name which equals the givenname
, then this accessor is returned, otherwisenull
.null
-values are allowed withinaccessors
.- Parameters:
accessors
- the array of accessorsname
- the name to search- Returns:
- an accessor of the list, corresponding to
name
, ornull
-
isDerived
public boolean isDerived()Determines whether this is a derived attribute or not.- Returns:
true
iff this is a derived attribute
-
isWritable
Checks whether a value for this attribute can be written to the given object.- Parameters:
object
- the objectasNode
-true
ifobject
is a node,false
ifobject
is an edgegs
- 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() -
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-
isContained
Checks whether this attribute is contained in the sorted arrayb
. The array has to be sorted in ascending order according to the order induced bycompareTo(Object)
.- Parameters:
b
- a sorted array of attributes- Returns:
true
iff this attribute is contained inb
-
setAttributeState
-
getAttributeState
-