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 classAbstractElement.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.voidclearAttributes()Remove all registered attributes.ObjectgetAttribute(String key)Get the attribute object bound to the given key.<T> TgetAttribute(String key, Class<T> clazz)Get the attribute object bound to the given key if it is an instance of the given class.intgetAttributeCount()Number of attributes stored in this element.<T> TgetFirstAttributeOf(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.ObjectgetFirstAttributeOf(String... keys)LikeElement.getAttribute(String), but returns the first existing attribute in a list of keys, instead of only one key.StringgetId()Unique identifier of this element.intgetIndex()The current index of this elementbooleanhasAttribute(String key)Does this element store a value for the given attribute key?booleanhasAttribute(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?voidremoveAttribute(String attribute)Remove an attribute.voidsetAttribute(String attribute, Object... values)Add or replace the value of an attribute.StringtoString()Override the Object method
-
Constructor Details
-
AbstractElement
New element.- Parameters:
id- The unique identifier of this element.
-
-
Method Details
-
getId
Description copied from interface:ElementUnique identifier of this element. -
getIndex
public int getIndex()Description copied from interface:ElementThe current index of this element -
getAttribute
Description copied from interface:ElementGet 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:
getAttributein 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:ElementLikeElement.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:
getFirstAttributeOfin 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:ElementGet 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:
getAttributein 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:ElementLikeElement.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:
getFirstAttributeOfin 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:ElementDoes 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:
hasAttributein 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:ElementDoes this element store a value for the given attribute key and this value is an instance of the given class?- Specified by:
hasAttributein 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:ElementStream over the attribute keys of the element. If no attribute exist, method will return empty stream.- Specified by:
attributeKeysin 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:ElementNumber of attributes stored in this element.- Specified by:
getAttributeCountin interfaceElement- Returns:
- the number of attributes.
-
clearAttributes
public void clearAttributes()Description copied from interface:ElementRemove all registered attributes. This includes numbers, labels and vectors.- Specified by:
clearAttributesin interfaceElement
-
setAttribute
Description copied from interface:ElementAdd 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:
setAttributein 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:ElementRemove an attribute. Non-existent attributes errors are ignored silently.- Specified by:
removeAttributein interfaceElement- Parameters:
attribute- Name of the attribute to remove.- Computational Complexity :
- O(log(n)) with n being the number of attributes of this element.
-