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
  • Constructor Details

    • AbstractElement

      public AbstractElement​(String id)
      New element.
      Parameters:
      id - The unique identifier of this element.
  • Method Details

    • getId

      public String getId()
      Description copied from interface: Element
      Unique identifier of this element.
      Specified by:
      getId in interface Element
      Returns:
      The identifier value.
    • getIndex

      public int getIndex()
      Description copied from interface: Element
      The current index of this element
      Specified by:
      getIndex in interface Element
      Returns:
      The index value
    • getAttribute

      public Object getAttribute​(String key)
      Description copied from interface: Element
      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.
      Specified by:
      getAttribute in interface Element
      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

      public Object getFirstAttributeOf​(String... keys)
      Description copied from interface: Element
      Like Element.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:
      getFirstAttributeOf in interface Element
      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

      public <T> T getAttribute​(String key, Class<T> clazz)
      Description copied from interface: Element
      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.
      Specified by:
      getAttribute in interface Element
      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

      public <T> T getFirstAttributeOf​(Class<T> clazz, String... keys)
      Description copied from interface: Element
      Like 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.
      Specified by:
      getFirstAttributeOf in interface Element
      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

      public boolean hasAttribute​(String key)
      Description copied from interface: Element
      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.
      Specified by:
      hasAttribute in interface Element
      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

      public boolean hasAttribute​(String key, Class<?> clazz)
      Description copied from interface: Element
      Does this element store a value for the given attribute key and this value is an instance of the given class?
      Specified by:
      hasAttribute in interface Element
      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

      public Stream<String> attributeKeys()
      Description copied from interface: Element
      Stream over the attribute keys of the element. If no attribute exist, method will return empty stream.
      Specified by:
      attributeKeys in interface Element
      Returns:
      a String stream corresponding to the keys of the attributes.
    • toString

      public String toString()
      Override the Object method
      Overrides:
      toString in class Object
    • getAttributeCount

      public int getAttributeCount()
      Description copied from interface: Element
      Number of attributes stored in this element.
      Specified by:
      getAttributeCount in interface Element
      Returns:
      the number of attributes.
    • clearAttributes

      public void clearAttributes()
      Description copied from interface: Element
      Remove all registered attributes. This includes numbers, labels and vectors.
      Specified by:
      clearAttributes in interface Element
    • setAttribute

      public void setAttribute​(String attribute, Object... values)
      Description copied from interface: Element
      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).
      Specified by:
      setAttribute in interface Element
      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

      public void removeAttribute​(String attribute)
      Description copied from interface: Element
      Remove an attribute. Non-existent attributes errors are ignored silently.
      Specified by:
      removeAttribute in interface Element
      Parameters:
      attribute - Name of the attribute to remove.
      Computational Complexity :
      O(log(n)) with n being the number of attributes of this element.