Class DOMTokenSetImpl

java.lang.Object
io.sf.carte.doc.DOMTokenSetImpl
All Implemented Interfaces:
DOMTokenList, Serializable, Iterable<String>

public class DOMTokenSetImpl extends Object implements DOMTokenList, Serializable
A sorted set implementation of the DOMTokenList interface.

The implementation is optimized for an use case where most instances of this class will only host a single token. Hence, it can hold a reference to a single String or to a sorted set, depending on the number of items in this list/set.

See Also:
  • Constructor Details

    • DOMTokenSetImpl

      public DOMTokenSetImpl()
  • Method Details

    • getValue

      public String getValue()
      Description copied from interface: DOMTokenList
      Gets the value of the collection as a String.
      Specified by:
      getValue in interface DOMTokenList
      Returns:
      the value of the collection as a String.
    • getSortedValue

      public String getSortedValue()
      Description copied from interface: DOMTokenList
      Gets the value of the collection as a String, with the tokens alphabetically ordered.
      Specified by:
      getSortedValue in interface DOMTokenList
      Returns:
      the value of the collection as an alphabetically ordered string.
    • setValue

      public void setValue(String value) throws DOMException
      Sets the value of the collection as a String.
      Parameters:
      value - the string value of the collection
      Throws:
      DOMException - SYNTAX_ERR if value is null.
    • checkMultipleToken

      public static boolean checkMultipleToken(String value)
      Utility method intended for cross-package internal use by the library.
      Parameters:
      value - the value to check.
      Returns:
      true if the value contains more than one token.
    • getLength

      public int getLength()
      Description copied from interface: DOMTokenList
      Gets the number of tokens stored in this collection.
      Specified by:
      getLength in interface DOMTokenList
      Returns:
      the number of tokens stored in this collection.
    • item

      public String item(int index)
      Description copied from interface: DOMTokenList
      Retrieves a token from the collection by its index.
      Specified by:
      item in interface DOMTokenList
      Parameters:
      index - the index.
      Returns:
      the token in the given place of this collection, or null if the index is negative, greater than or equal to the length of this collection.
    • iterator

      public Iterator<String> iterator()
      Description copied from interface: DOMTokenList
      Obtain an iterator over the members of this set.
      Specified by:
      iterator in interface DOMTokenList
      Specified by:
      iterator in interface Iterable<String>
      Returns:
      an iterator over the members of this set.
    • contains

      public boolean contains(String token)
      Description copied from interface: DOMTokenList
      Does this collection contains this token?
      Specified by:
      contains in interface DOMTokenList
      Parameters:
      token - the token.
      Returns:
      true if the list contains the given token, false otherwise.
    • containsAll

      public boolean containsAll(DOMTokenList otherlist)
      Description copied from interface: DOMTokenList
      Does this collection contain all the tokens in the supplied DOMTokenList?
      Specified by:
      containsAll in interface DOMTokenList
      Parameters:
      otherlist - another DOMTokenList.
      Returns:
      true if this list contains all the tokens in the given otherlist, false otherwise.
    • containsAll

      public boolean containsAll(Collection<String> tokenSet)
      Description copied from interface: DOMTokenList
      Does this collection contain all the tokens in the given collection?
      Specified by:
      containsAll in interface DOMTokenList
      Parameters:
      tokenSet - the collection of tokens.
      Returns:
      true if the list contains all the tokens in the given set, false otherwise.
    • add

      public void add(String token) throws DOMException
      Description copied from interface: DOMTokenList
      Adds the given token to this collection.

      If the set already contains the token, then do nothing.

      Specified by:
      add in interface DOMTokenList
      Parameters:
      token - the token to add.
      Throws:
      DOMException - SYNTAX_ERR if the token is null or empty. INVALID_CHARACTER_ERR if the token contains spaces.
    • addUnchecked

      protected void addUnchecked(String token) throws DOMException
      Throws:
      DOMException
    • remove

      public void remove(String token) throws DOMException
      Description copied from interface: DOMTokenList
      Removes the given token from this collection.
      Specified by:
      remove in interface DOMTokenList
      Parameters:
      token - the token to remove.
      Throws:
      DOMException - SYNTAX_ERR if the token is null or empty. INVALID_CHARACTER_ERR if the token contains spaces.
    • removeUnchecked

      protected void removeUnchecked(String token) throws DOMException
      Throws:
      DOMException
    • toggle

      public boolean toggle(String token) throws DOMException
      Description copied from interface: DOMTokenList
      If the given token exists in this collection, remove it; otherwise add it.
      Specified by:
      toggle in interface DOMTokenList
      Parameters:
      token - the token to toggle.
      Returns:
      true if the token is added, false if it is removed.
      Throws:
      DOMException - SYNTAX_ERR if the token is null or empty. INVALID_CHARACTER_ERR if the token contains spaces.
    • toggleUnchecked

      protected boolean toggleUnchecked(String token) throws DOMException
      Throws:
      DOMException
    • replace

      public void replace(String oldToken, String newToken) throws DOMException
      Description copied from interface: DOMTokenList
      Replaces an existing token with a new token.

      If the set does not contain the token, do nothing.

      Specified by:
      replace in interface DOMTokenList
      Parameters:
      oldToken - the token that has to be replaced.
      newToken - the new token.
      Throws:
      DOMException - SYNTAX_ERR if any of the tokens is null or empty. INVALID_CHARACTER_ERR if any of the tokens contains spaces.
    • replaceUnchecked

      protected void replaceUnchecked(String oldToken, String newToken) throws DOMException
      Throws:
      DOMException
    • clear

      public void clear()
      Empty this set.

      After calling this method, the length of this set is zero.

    • argumentCheckVoidSpaces

      protected void argumentCheckVoidSpaces(String token) throws DOMException
      Throws:
      DOMException
    • toString

      public String toString()
      Overrides:
      toString in class Object