Class TokenList

java.lang.Object
org.openhab.core.voice.text.TokenList

public class TokenList extends Object
A helper to parse a sequence of tokens. This class is immutable.
Author:
Tilman Kamp - Initial contribution
  • Constructor Details Link icon

    • TokenList Link icon

      public TokenList(List<String> list)
      Constructs a new instance.
      Parameters:
      list - of the initial tokens
  • Method Details Link icon

    • head Link icon

      public String head()
      Gets the first token of the list.
      Returns:
      the first token of the list
    • tail Link icon

      public String tail()
      Gets the last token of the list.
      Returns:
      the last token of the list
    • eof Link icon

      public boolean eof()
      Checks, if the list is empty.
      Returns:
      if the list is empty
    • size Link icon

      public int size()
      Retrieves the token count within the list.
      Returns:
      token count
    • checkHead Link icon

      public boolean checkHead(String... alternatives)
      Checks for the first token of the list. If it is equal to one of the provided alternatives, it will succeed.
      Parameters:
      alternatives - Allowed token values for the list's first token. If empty, all token values are allowed.
      Returns:
      True, if first token is equal to one of the alternatives or if no alternatives were provided. False otherwise. Always false, if there is no first token (if the list is empty).
    • checkTail Link icon

      public boolean checkTail(String... alternatives)
      Checks for the last token of the list. If it is equal to one of the provided alternatives, it will succeed.
      Parameters:
      alternatives - Allowed token values for the list's last token. If empty, all token values are allowed.
      Returns:
      True, if last token is equal to one of the alternatives or if no alternatives were provided. False otherwise. Always false, if there is no last token (if the list is empty).
    • peekHead Link icon

      public String peekHead(String... alternatives)
      Retrieves the first token of the list, in case it is equal to one of the provided alternatives.
      Parameters:
      alternatives - Allowed token values for the list's first token. If empty, all token values are allowed.
      Returns:
      First token, if it is equal to one of the alternatives or if no alternatives were provided. Null otherwise. Always null, if there is no first token (if the list is empty).
    • peekTail Link icon

      public String peekTail(String... alternatives)
      Retrieves the last token of the list, in case it is equal to one of the provided alternatives.
      Parameters:
      alternatives - Allowed token values for the list's last token. If empty, all token values are allowed.
      Returns:
      Last token, if it is equal to one of the alternatives or if no alternatives were provided. Null otherwise. Always null, if there is no last token (if the list is empty).
    • skipHead Link icon

      public TokenList skipHead()
      Creates a new list without the first token.
      Returns:
      a new list without the first token
    • skipTail Link icon

      public TokenList skipTail()
      Creates a new list without the last token.
      Returns:
      a new list without the last token