public interface Element
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)
.
Implementing classes should indicate the complexity of their implementation for each method.
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.
|
default java.lang.Object[] |
getArray(java.lang.String key)
Get the array of objects bound to key.
|
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
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
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
|
default java.lang.CharSequence |
getLabel(java.lang.String key)
Get the label string bound to the given key key.
|
default java.util.Map<?,?> |
getMap(java.lang.String key)
Get the map bound to key.
|
default double |
getNumber(java.lang.String key)
Get the number bound to key.
|
default java.util.List<? extends java.lang.Number> |
getVector(java.lang.String key)
Get the vector of number bound to key.
|
default boolean |
hasArray(java.lang.String key)
Does this element store an array value for the given key?
|
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?
|
default boolean |
hasLabel(java.lang.String key)
Does this element store a label value for the given key?
|
default boolean |
hasMap(java.lang.String key)
Does this element store a map value for the given key?
|
default boolean |
hasNumber(java.lang.String key)
Does this element store a number for the given key?
|
default boolean |
hasVector(java.lang.String key)
Does this element store a vector value for the given key?
|
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.
|
default void |
setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Add or replace each attribute found in attributes.
|
java.lang.String getId()
int getIndex()
java.lang.Object getAttribute(java.lang.String key)
key
- Name of the attribute to search.java.lang.Object getFirstAttributeOf(java.lang.String... keys)
getAttribute(String)
, but returns the first existing attribute
in a list of keys, instead of only one key. The key list order matters.keys
- Several strings naming attributes.<T> T getAttribute(java.lang.String key, java.lang.Class<T> clazz)
key
- The attribute name to search.clazz
- The expected attribute class.<T> T getFirstAttributeOf(java.lang.Class<T> clazz, java.lang.String... keys)
getAttribute(String, Class)
, but returns the first existing
attribute in a list of keys, instead of only one key. The key list order
matters.clazz
- The class the attribute must be instance of.keys
- Several string naming attributes.default java.lang.CharSequence getLabel(java.lang.String key)
key
- The label to search.default double getNumber(java.lang.String key)
key
- The name of the number to search.default java.util.List<? extends java.lang.Number> getVector(java.lang.String key)
List
of Number
objects.key
- The name of the number to search.default java.lang.Object[] getArray(java.lang.String key)
key
- The name of the array to search.default java.util.Map<?,?> getMap(java.lang.String key)
CompoundAttribute
interface are considered like maps since they can
be transformed to a map. If an attribute with the same name exists but is not
a map, 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.key
- The name of the map to search.boolean hasAttribute(java.lang.String key)
key
- The name of the attribute to search.boolean hasAttribute(java.lang.String key, java.lang.Class<?> clazz)
key
- The name of the attribute to search.clazz
- The expected class of the attribute value.default boolean hasLabel(java.lang.String key)
key
- The name of the label.default boolean hasNumber(java.lang.String key)
key
- The name of the number.default boolean hasVector(java.lang.String key)
key
- The name of the vector.default boolean hasArray(java.lang.String key)
key
- The name of the array.default boolean hasMap(java.lang.String key)
Map
) or objects that implement the
CompoundAttribute
class.key
- The name of the hash.java.util.stream.Stream<java.lang.String> attributeKeys()
void clearAttributes()
void setAttribute(java.lang.String attribute, java.lang.Object... values)
attribute
- The attribute name.values
- The attribute value or set of values.default void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
attributes
- A set of (key,value) pairs.void removeAttribute(java.lang.String attribute)
attribute
- Name of the attribute to remove.int getAttributeCount()