Class OneAttributeElement

java.lang.Object
org.graphstream.graph.implementations.OneAttributeElement
All Implemented Interfaces:
Element

public abstract class OneAttributeElement
extends Object
implements Element
An implementation of an Element.

It allows only one attribute and has no internal map structure. It is not used and may be removed.

  • Constructor Details

    • OneAttributeElement

      public OneAttributeElement​(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.
    • 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.
    • 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.
    • 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.
    • 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.
    • getLabel

      public CharSequence getLabel​(String key)
      Description copied from interface: Element
      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.
      Specified by:
      getLabel in interface Element
      Parameters:
      key - The label to search.
      Returns:
      The label string value or null if not found.
    • getNumber

      public double getNumber​(String key)
      Description copied from interface: Element
      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.
      Specified by:
      getNumber in interface Element
      Parameters:
      key - The name of the number to search.
      Returns:
      The number value or NaN if not found.
    • getVector

      public ArrayList<? extends Number> getVector​(String key)
      Description copied from interface: Element
      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.
      Specified by:
      getVector in interface Element
      Parameters:
      key - The name of the number to search.
      Returns:
      The vector of numbers or null if not found.
    • 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.
    • 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.
    • hasLabel

      public boolean hasLabel​(String key)
      Description copied from interface: Element
      Does this element store a label value for the given key? A label is an attribute whose value is a char sequence.
      Specified by:
      hasLabel in interface Element
      Parameters:
      key - The name of the label.
      Returns:
      True if a value is present for this attribute and implements CharSequence.
    • hasNumber

      public boolean hasNumber​(String key)
      Description copied from interface: Element
      Does this element store a number for the given key? A number is an attribute whose value is an instance of Number.
      Specified by:
      hasNumber in interface Element
      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).
    • hasVector

      public boolean hasVector​(String key)
      Description copied from interface: Element
      Does this element store a vector value for the given key? A vector is an attribute whose value is a sequence of numbers.
      Specified by:
      hasVector in interface Element
      Parameters:
      key - The name of the vector.
      Returns:
      True if a value is present for this attribute and can contain a sequence of numbers.
    • getAttributeKeyIterator

      public Iterator<String> getAttributeKeyIterator()
    • getAttributeMap

      public Map<String,​Object> getAttributeMap()
    • toString

      public String toString()
      Override the Object method
      Overrides:
      toString in class Object
    • 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
    • addAttribute

      public void addAttribute​(String attribute, Object value)
    • changeAttribute

      public void changeAttribute​(String attribute, Object value)
    • setAttributes

      public void setAttributes​(Map<String,​Object> attributes)
      Description copied from interface: Element
      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.
      Specified by:
      setAttributes in interface Element
      Parameters:
      attributes - A set of (key,value) pairs.
    • 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.