Interface Element

All Known Subinterfaces:
Edge, Graph, Node
All Known Implementing Classes:
AbstractEdge, AbstractElement, AbstractGraph, AbstractNode, AdjacencyListGraph, AdjacencyListNode, DefaultGraph, GraphicEdge, GraphicElement, GraphicGraph, GraphicNode, GraphicSprite, MultiGraph, MultiNode, OneAttributeElement, SingleGraph, SingleNode, Sprite

public interface Element
An element is a part of a graph (node, edge, the graph itself).

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).

Important

Implementing classes should indicate the complexity of their implementation for each method.

Since:
July 12 2007
  • Method Details

    • getId

      String getId()
      Unique identifier of this element.
      Returns:
      The identifier value.
    • getIndex

      int getIndex()
      The current index of this element
      Returns:
      The index value
    • getAttribute

      Object getAttribute​(String key)
      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.
      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.
    • getFirstAttributeOf

      Object getFirstAttributeOf​(String... keys)
      Like getAttribute(String), but returns the first existing attribute in a list of keys, instead of only one key. The key list order matters.
      Parameters:
      keys - Several strings naming attributes.
      Returns:
      The first attribute that exists.
    • getAttribute

      <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. Some The returned value maybe null to indicate the attribute does not exists or is not an instance of the given class.
      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.
    • getFirstAttributeOf

      <T> T getFirstAttributeOf​(Class<T> clazz, String... keys)
      Like getAttribute(String, Class), but returns the first existing attribute in a list of keys, instead of only one key. The key list order matters.
      Parameters:
      clazz - The class the attribute must be instance of.
      keys - Several string naming attributes.
      Returns:
      The first attribute that exists.
    • getLabel

      default CharSequence getLabel​(String key)
      Get the label string bound to the given key key. Labels are special attributes whose value is a character sequence. If an attribute with the same name exists but is not a character sequence, null is returned.
      Parameters:
      key - The label to search.
      Returns:
      The label string value or null if not found.
    • getNumber

      default double getNumber​(String key)
      Get the number bound to key. Numbers are special attributes whose value is an instance of Number. If an attribute with the same name exists but is not a Number, NaN is returned.
      Parameters:
      key - The name of the number to search.
      Returns:
      The number value or NaN if not found.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • getVector

      default List<? extends Number> getVector​(String key)
      Get the vector of number bound to key. Vectors of numbers are special attributes whose value is a sequence of numbers. If an attribute with the same name exists but is not a vector of number, null is returned. A vector of number is a non-empty List of Number objects.
      Parameters:
      key - The name of the number to search.
      Returns:
      The vector of numbers or null if not found.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • getArray

      default Object[] getArray​(String key)
      Get the array of objects bound to key. Arrays of objects are special attributes whose value is a sequence of objects. If an attribute with the same name exists but is not an array, null is returned.
      Parameters:
      key - The name of the array to search.
      Returns:
      The array of objects or null if not found.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • getMap

      default Map<?,​?> getMap​(String key)
      Get the map bound to key. Maps are special attributes whose value is a set of pairs (name,object). Instances of object implementing the 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.
      Parameters:
      key - The name of the map to search.
      Returns:
      The map or null if not found.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • hasAttribute

      boolean hasAttribute​(String key)
      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.
      Parameters:
      key - The name of the attribute to search.
      Returns:
      True if a value is present for this attribute.
    • hasAttribute

      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?
      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.
    • hasLabel

      default boolean hasLabel​(String key)
      Does this element store a label value for the given key? A label is an attribute whose value is a char sequence.
      Parameters:
      key - The name of the label.
      Returns:
      True if a value is present for this attribute and implements CharSequence.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • hasNumber

      default boolean hasNumber​(String key)
      Does this element store a number for the given key? A number is an attribute whose value is an instance of Number.
      Parameters:
      key - The name of the number.
      Returns:
      True if a value is present for this attribute and can contain a double (inherits from Number).
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • hasVector

      default boolean hasVector​(String key)
      Does this element store a vector value for the given key? A vector is an attribute whose value is a sequence of numbers.
      Parameters:
      key - The name of the vector.
      Returns:
      True if a value is present for this attribute and can contain a sequence of numbers.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • hasArray

      default boolean hasArray​(String key)
      Does this element store an array value for the given key? Only object arrays (instance of Object[]) are considered as array here.
      Parameters:
      key - The name of the array.
      Returns:
      True if a value is present for this attribute and can contain an array object.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • hasMap

      default boolean hasMap​(String key)
      Does this element store a map value for the given key? A map is a set of pairs (key,value) (Map) or objects that implement the CompoundAttribute class.
      Parameters:
      key - The name of the hash.
      Returns:
      True if a value is present for this attribute and can contain a hash.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • attributeKeys

      Stream<String> attributeKeys()
      Stream over the attribute keys of the element. If no attribute exist, method will return empty stream.
      Returns:
      a String stream corresponding to the keys of the attributes.
    • clearAttributes

      void clearAttributes()
      Remove all registered attributes. This includes numbers, labels and vectors.
    • setAttribute

      void setAttribute​(String attribute, Object... values)
      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).
      Parameters:
      attribute - The attribute name.
      values - The attribute value or set of values.
    • setAttributes

      default void setAttributes​(Map<String,​Object> attributes)
      Add or replace each attribute found in attributes. 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.
      Parameters:
      attributes - A set of (key,value) pairs.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.
    • removeAttribute

      void removeAttribute​(String attribute)
      Remove an attribute. Non-existent attributes errors are ignored silently.
      Parameters:
      attribute - Name of the attribute to remove.
    • getAttributeCount

      int getAttributeCount()
      Number of attributes stored in this element.
      Returns:
      the number of attributes.