Class AbstractElement
java.lang.Object
org.graphstream.graph.implementations.AbstractElement
- All Implemented Interfaces:
Element
- Direct Known Subclasses:
AbstractEdge
,AbstractGraph
,AbstractNode
,GraphicElement
,GraphicGraph
public abstract class AbstractElement extends Object implements Element
A base implementation of an element.
This class is the Base class for Node
,
Edge
and Graph
.
An element is made of an unique and arbitrary identifier that identifies it,
and a set of attributes.
- Since:
- 20040910
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractElement.AttributeChangeEvent
-
Constructor Summary
Constructors Constructor Description AbstractElement(String id)
New element. -
Method Summary
Modifier and Type Method Description Stream<String>
attributeKeys()
Stream over the attribute keys of the element.void
clearAttributes()
Remove all registered attributes.Object
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.<T> T
getFirstAttributeOf(Class<T> clazz, String... keys)
LikeElement.getAttribute(String, Class)
, but returns the first existing attribute in a list of keys, instead of only one key.Object
getFirstAttributeOf(String... keys)
LikeElement.getAttribute(String)
, but returns the first existing attribute in a list of keys, instead of only one key.String
getId()
Unique identifier of this element.int
getIndex()
The current index of this elementboolean
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?void
removeAttribute(String attribute)
Remove an attribute.void
setAttribute(String attribute, Object... values)
Add or replace the value of an attribute.String
toString()
Override the Object method
-
Constructor Details
-
AbstractElement
New element.- Parameters:
id
- The unique identifier of this element.
-
-
Method Details
-
getId
Description copied from interface:Element
Unique identifier of this element. -
getIndex
public int getIndex()Description copied from interface:Element
The current index of this element -
getAttribute
Description copied from interface:Element
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.- Specified by:
getAttribute
in interfaceElement
- 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.
- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-
getFirstAttributeOf
Description copied from interface:Element
LikeElement.getAttribute(String)
, but returns the first existing attribute in a list of keys, instead of only one key. The key list order matters.- Specified by:
getFirstAttributeOf
in interfaceElement
- Parameters:
keys
- Several strings naming attributes.- Returns:
- The first attribute that exists.
- Computational Complexity :
- O(log(n*m)) with n being the number of attributes of this element and m the number of keys given.
-
getAttribute
Description copied from interface:Element
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.- Specified by:
getAttribute
in interfaceElement
- 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.
- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-
getFirstAttributeOf
Description copied from interface:Element
LikeElement.getAttribute(String, Class)
, but returns the first existing attribute in a list of keys, instead of only one key. The key list order matters.- Specified by:
getFirstAttributeOf
in interfaceElement
- Parameters:
clazz
- The class the attribute must be instance of.keys
- Several string naming attributes.- Returns:
- The first attribute that exists.
- Computational Complexity :
- O(log(n*m)) with n being the number of attributes of this element and m the number of keys given.
-
hasAttribute
Description copied from interface:Element
Does this element store a value for the given attribute key? Note that returning true here does not mean that calling getAttribute with the same key will not return null since attribute values can be null. This method just checks if the key is present, with no test on the value.- Specified by:
hasAttribute
in interfaceElement
- Parameters:
key
- The name of the attribute to search.- Returns:
- True if a value is present for this attribute.
- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-
hasAttribute
Description copied from interface:Element
Does this element store a value for the given attribute key and this value is an instance of the given class?- Specified by:
hasAttribute
in interfaceElement
- 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.
- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-
attributeKeys
Description copied from interface:Element
Stream over the attribute keys of the element. If no attribute exist, method will return empty stream.- Specified by:
attributeKeys
in interfaceElement
- Returns:
- a String stream corresponding to the keys of the attributes.
-
toString
Override the Object method -
getAttributeCount
public int getAttributeCount()Description copied from interface:Element
Number of attributes stored in this element.- Specified by:
getAttributeCount
in interfaceElement
- Returns:
- the number of attributes.
-
clearAttributes
public void clearAttributes()Description copied from interface:Element
Remove all registered attributes. This includes numbers, labels and vectors.- Specified by:
clearAttributes
in interfaceElement
-
setAttribute
Description copied from interface:Element
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).- Specified by:
setAttribute
in interfaceElement
- Parameters:
attribute
- The attribute name.values
- The attribute value or set of values.- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-
removeAttribute
Description copied from interface:Element
Remove an attribute. Non-existent attributes errors are ignored silently.- Specified by:
removeAttribute
in interfaceElement
- Parameters:
attribute
- Name of the attribute to remove.- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-