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()
Element
public int getIndex()
Element
public java.lang.Object getAttribute(java.lang.String key)
Element
getAttribute
in interface Element
key
- Name of the attribute to search.public java.lang.Object getFirstAttributeOf(java.lang.String... keys)
Element
Element.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 Element
keys
- Several strings naming attributes.public <T> T getAttribute(java.lang.String key, java.lang.Class<T> clazz)
Element
getAttribute
in interface Element
key
- The attribute name to search.clazz
- The expected attribute class.public <T> T getFirstAttributeOf(java.lang.Class<T> clazz, java.lang.String... keys)
Element
Element.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 Element
clazz
- The class the attribute must be instance of.keys
- Several string naming attributes.public boolean hasAttribute(java.lang.String key)
Element
hasAttribute
in interface Element
key
- The name of the attribute to search.public boolean hasAttribute(java.lang.String key, java.lang.Class<?> clazz)
Element
hasAttribute
in interface Element
key
- The name of the attribute to search.clazz
- The expected class of the attribute value.public java.util.stream.Stream<java.lang.String> attributeKeys()
Element
attributeKeys
in interface Element
public java.lang.String toString()
toString
in class java.lang.Object
public int getAttributeCount()
Element
getAttributeCount
in interface Element
public void clearAttributes()
Element
clearAttributes
in interface Element
public void setAttribute(java.lang.String attribute, java.lang.Object... values)
Element
setAttribute
in interface Element
attribute
- The attribute name.values
- The attribute value or set of values.public void removeAttribute(java.lang.String attribute)
Element
removeAttribute
in interface Element
attribute
- Name of the attribute to remove.