org.graphstream.graph
Interface Element

All Known Subinterfaces:
Edge, Graph, Node
All Known Implementing Classes:
AbstractEdge, AbstractElement, AbstractGraph, AbstractNode, AdjacencyListGraph, AdjacencyListNode, DefaultGraph, GraphicEdge, GraphicElement, GraphicGraph, GraphicNode, GraphicSprite, MultiGraph, MultiNode, OneAttributeElement, SingleGraph, SingleNode, Sprite

public interface Element

An element is a part of a graph (node, edge, the graph itself).

An interface that defines common method to manipulate identifiers, attributes and indices of the elements (graph, nodes and edges) of a graph.

*

Attributes can be any object and are identified by arbitrary strings. Some attributes are stored as numbers or strings and are in this case named number, label or vector. There are utility methods to handle these attributes (getNumber(String), getLabel(String)) or getVector(String), however they are also accessible through the more general method getAttribute(String).

Important

Implementing classes should indicate the complexity of their implementation for each method.

Since:
July 12 2007

Method Summary
 void addAttribute(String attribute, Object... values)
          Add or replace the value of an attribute.
 void addAttributes(Map<String,Object> attributes)
          Add or replace each attribute found in attributes.
 void changeAttribute(String attribute, Object... values)
          Like addAttribute(String, Object...) but for consistency.
 void clearAttributes()
          Remove all registered attributes.
 Object[] getArray(String key)
          Get the array of objects bound to key.
<T> T
getAttribute(String key)
          Get the attribute object bound to the given key.
<T> T
getAttribute(String key, Class<T> clazz)
          Get the attribute object bound to the given key if it is an instance of the given class.
 int getAttributeCount()
          Number of attributes stored in this element.
 Iterator<String> getAttributeKeyIterator()
          Iterator on all attributes keys.
 Iterable<String> getAttributeKeySet()
          An iterable view on the set of attributes keys usable with the for-each loop.
<T> T
getFirstAttributeOf(Class<T> clazz, String... keys)
          Like getAttribute(String, Class), but returns the first existing attribute in a list of keys, instead of only one key.
<T> T
getFirstAttributeOf(String... keys)
          Like getAttribute(String), but returns the first existing attribute in a list of keys, instead of only one key.
 HashMap<?,?> getHash(String key)
          Get the hash bound to key.
 String getId()
          Unique identifier of this element.
 int getIndex()
          The current index of this element
 CharSequence getLabel(String key)
          Get the label string bound to the given key key.
 double getNumber(String key)
          Get the number bound to key.
 ArrayList<? extends Number> getVector(String key)
          Get the vector of number bound to key.
 boolean hasArray(String key)
          Does this element store an array value for the given key?
 boolean hasAttribute(String key)
          Does this element store a value for the given attribute key?
 boolean hasAttribute(String key, Class<?> clazz)
          Does this element store a value for the given attribute key and this value is an instance of the given class?
 boolean hasHash(String key)
          Does this element store a hash value for the given key?
 boolean hasLabel(String key)
          Does this element store a label value for the given key?
 boolean hasNumber(String key)
          Does this element store a number for the given key?
 boolean hasVector(String key)
          Does this element store a vector value for the given key?
 void removeAttribute(String attribute)
          Remove an attribute.
 void setAttribute(String attribute, Object... values)
          Like addAttribute(String, Object...) but for consistency.
 

Method Detail

getId

String getId()
Unique identifier of this element.

Returns:
The identifier value.

getIndex

int getIndex()
The current index of this element

Returns:
The index value

getAttribute

<T> T getAttribute(String key)
Get the attribute object bound to the given key. The returned value may be null to indicate the attribute does not exists or is not supported.

Parameters:
key - Name of the attribute to search.
Returns:
The object bound to the given key or null if no object match this attribute name.

getFirstAttributeOf

<T> T getFirstAttributeOf(String... keys)
Like getAttribute(String), but returns the first existing attribute in a list of keys, instead of only one key. The key list order matters.

Parameters:
keys - Several strings naming attributes.
Returns:
The first attribute that exists.

getAttribute

<T> T getAttribute(String key,
                   Class<T> clazz)
Get the attribute object bound to the given key if it is an instance of the given class. Some The returned value maybe null to indicate the attribute does not exists or is not an instance of the given class.

Parameters:
key - The attribute name to search.
clazz - The expected attribute class.
Returns:
The object bound to the given key or null if no object match this attribute.

getFirstAttributeOf

<T> T getFirstAttributeOf(Class<T> clazz,
                          String... keys)
Like getAttribute(String, Class), but returns the first existing attribute in a list of keys, instead of only one key. The key list order matters.

Parameters:
clazz - The class the attribute must be instance of.
keys - Several string naming attributes.
Returns:
The first attribute that exists.

getLabel

CharSequence getLabel(String key)
Get the label string bound to the given key key. Labels are special attributes whose value is a character sequence. If an attribute with the same name exists but is not a character sequence, null is returned.

Parameters:
key - The label to search.
Returns:
The label string value or null if not found.

getNumber

double getNumber(String key)
Get the number bound to key. Numbers are special attributes whose value is an instance of Number. If an attribute with the same name exists but is not a Number, NaN is returned.

Parameters:
key - The name of the number to search.
Returns:
The number value or NaN if not found.

getVector

ArrayList<? extends Number> getVector(String key)
Get the vector of number bound to key. Vectors of numbers are special attributes whose value is a sequence of numbers. If an attribute with the same name exists but is not a vector of number, null is returned.

Parameters:
key - The name of the number to search.
Returns:
The vector of numbers or null if not found.

getArray

Object[] getArray(String key)
Get the array of objects bound to key. Arrays of objects are special attributes whose value is a sequence of objects. If an attribute with the same name exists but is not an array, null is returned.

Parameters:
key - The name of the array to search.
Returns:
The array of objects or null if not found.

getHash

HashMap<?,?> getHash(String key)
Get the hash bound to key. Hashes are special attributes whose value is a set of pairs (name,object). Instances of object implementing the CompoundAttribute interface are considered like hashes since they can be transformed to a hash. If an attribute with the same name exists but is not a hash, null is returned. We cannot enforce the type of the key. It is considered a string and you should use "Object.toString()" to get it.

Parameters:
key - The name of the hash to search.
Returns:
The hash or null if not found.

hasAttribute

boolean hasAttribute(String key)
Does this element store a value for the given attribute key?

Parameters:
key - The name of the attribute to search.
Returns:
True if a value is present for this attribute.

hasAttribute

boolean hasAttribute(String key,
                     Class<?> clazz)
Does this element store a value for the given attribute key and this value is an instance of the given class?

Parameters:
key - The name of the attribute to search.
clazz - The expected class of the attribute value.
Returns:
True if a value is present for this attribute.

hasLabel

boolean hasLabel(String key)
Does this element store a label value for the given key? A label is an attribute whose value is a string.

Parameters:
key - The name of the label.
Returns:
True if a value is present for this attribute and implements CharSequence.

hasNumber

boolean hasNumber(String key)
Does this element store a number for the given key? A number is an attribute whose value is an instance of Number.

Parameters:
key - The name of the number.
Returns:
True if a value is present for this attribute and can contain a double (inherits from Number).

hasVector

boolean hasVector(String key)
Does this element store a vector value for the given key? A vector is an attribute whose value is a sequence of numbers.

Parameters:
key - The name of the vector.
Returns:
True if a value is present for this attribute and can contain a sequence of numbers.

hasArray

boolean hasArray(String key)
Does this element store an array value for the given key? A vector is an attribute whose value is an array of objects.

Parameters:
key - The name of the array.
Returns:
True if a value is present for this attribute and can contain an array object.

hasHash

boolean hasHash(String key)
Does this element store a hash value for the given key? A hash is a set of pairs (key,value) or objects that implement the CompoundAttribute class.

Parameters:
key - The name of the hash.
Returns:
True if a value is present for this attribute and can contain a hash.

getAttributeKeyIterator

Iterator<String> getAttributeKeyIterator()
Iterator on all attributes keys.

Returns:
An iterator on the key set of attributes.

getAttributeKeySet

Iterable<String> getAttributeKeySet()
An iterable view on the set of attributes keys usable with the for-each loop.

Returns:
an iterable view on each attribute key, null if there are no attributes.

clearAttributes

void clearAttributes()
Remove all registered attributes. This includes numbers, labels and vectors.


addAttribute

void addAttribute(String attribute,
                  Object... values)
Add or replace the value of an attribute. Existing attributes are overwritten silently. All classes inheriting from Number can be considered as numbers. All classes inheriting from CharSequence can be considered as labels. You can pass zero, one or more arguments for the attribute values. If no value is given, a boolean with value "true" is added. If there is more than one value, an array is stored. If there is only one value, the value is stored (but not in an array).

Parameters:
attribute - The attribute name.
values - The attribute value or set of values.

changeAttribute

void changeAttribute(String attribute,
                     Object... values)
Like addAttribute(String, Object...) but for consistency.

Parameters:
attribute - The attribute name.
values - The attribute value or array of values.
See Also:
addAttribute(String, Object...)

setAttribute

void setAttribute(String attribute,
                  Object... values)
Like addAttribute(String, Object...) but for consistency.

Parameters:
attribute - The attribute name.
values - The attribute value or array of values.
See Also:
addAttribute(String, Object...)

addAttributes

void addAttributes(Map<String,Object> attributes)
Add or replace each attribute found in attributes. Existing attributes are overwritten silently. All classes inheriting from Number can be considered as numbers. All classes inheriting from CharSequence can be considered as labels.

Parameters:
attributes - A set of (key,value) pairs.

removeAttribute

void removeAttribute(String attribute)
Remove an attribute. Non-existent attributes errors are ignored silently.

Parameters:
attribute - Name of the attribute to remove.

getAttributeCount

int getAttributeCount()
Number of attributes stored in this element.

Returns:
the number of attributes.


Copyright © 2013. All Rights Reserved.