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

    • TokenList

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

    • head

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

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

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

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

      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

      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

      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

      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

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

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