public abstract class AbstractElement extends java.lang.Object implements 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.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractElement.AttributeChangeEvent |
| Constructor and Description |
|---|
AbstractElement(java.lang.String id)
New element.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.stream.Stream<java.lang.String> |
attributeKeys()
Stream over the attribute keys of the element.
|
void |
clearAttributes()
Remove all registered attributes.
|
java.lang.Object |
getAttribute(java.lang.String key)
Get the attribute object bound to the given key.
|
<T> T |
getAttribute(java.lang.String key,
java.lang.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(java.lang.Class<T> clazz,
java.lang.String... keys)
Like
Element.getAttribute(String, Class), but returns the first existing
attribute in a list of keys, instead of only one key. |
java.lang.Object |
getFirstAttributeOf(java.lang.String... keys)
Like
Element.getAttribute(String), but returns the first existing attribute
in a list of keys, instead of only one key. |
java.lang.String |
getId()
Unique identifier of this element.
|
int |
getIndex()
The current index of this element
|
boolean |
hasAttribute(java.lang.String key)
Does this element store a value for the given attribute key?
|
boolean |
hasAttribute(java.lang.String key,
java.lang.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(java.lang.String attribute)
Remove an attribute.
|
void |
setAttribute(java.lang.String attribute,
java.lang.Object... values)
Add or replace the value of an attribute.
|
java.lang.String |
toString()
Override the Object method
|
public AbstractElement(java.lang.String id)
id - The unique identifier of this element.public java.lang.String getId()
Elementpublic int getIndex()
Elementpublic java.lang.Object getAttribute(java.lang.String key)
ElementgetAttribute in interface Elementkey - Name of the attribute to search.public java.lang.Object getFirstAttributeOf(java.lang.String... keys)
ElementElement.getAttribute(String), but returns the first existing attribute
in a list of keys, instead of only one key. The key list order matters.getFirstAttributeOf in interface Elementkeys - Several strings naming attributes.public <T> T getAttribute(java.lang.String key,
java.lang.Class<T> clazz)
ElementgetAttribute in interface Elementkey - The attribute name to search.clazz - The expected attribute class.public <T> T getFirstAttributeOf(java.lang.Class<T> clazz,
java.lang.String... keys)
ElementElement.getAttribute(String, Class), but returns the first existing
attribute in a list of keys, instead of only one key. The key list order
matters.getFirstAttributeOf in interface Elementclazz - The class the attribute must be instance of.keys - Several string naming attributes.public boolean hasAttribute(java.lang.String key)
ElementhasAttribute in interface Elementkey - The name of the attribute to search.public boolean hasAttribute(java.lang.String key,
java.lang.Class<?> clazz)
ElementhasAttribute in interface Elementkey - The name of the attribute to search.clazz - The expected class of the attribute value.public java.util.stream.Stream<java.lang.String> attributeKeys()
ElementattributeKeys in interface Elementpublic java.lang.String toString()
toString in class java.lang.Objectpublic int getAttributeCount()
ElementgetAttributeCount in interface Elementpublic void clearAttributes()
ElementclearAttributes in interface Elementpublic void setAttribute(java.lang.String attribute,
java.lang.Object... values)
ElementsetAttribute in interface Elementattribute - The attribute name.values - The attribute value or set of values.public void removeAttribute(java.lang.String attribute)
ElementremoveAttribute in interface Elementattribute - Name of the attribute to remove.