Package org.openhab.core.voice.text
Class TokenList
java.lang.Object
org.openhab.core.voice.text.TokenList
A helper to parse a sequence of tokens. This class is immutable.
- Author:
- Tilman Kamp - Initial contribution
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks for the first token of the list.boolean
Checks for the last token of the list.boolean
eof()
Checks, if the list is empty.head()
Gets the first token of the list.Retrieves the first token of the list, in case it is equal to one of the provided alternatives.Retrieves the last token of the list, in case it is equal to one of the provided alternatives.int
size()
Retrieves the token count within the list.skipHead()
Creates a new list without the first token.skipTail()
Creates a new list without the last token.tail()
Gets the last token of the list.
-
Constructor Details
-
TokenList
Constructs a new instance.- Parameters:
list
- of the initial tokens
-
-
Method Details
-
head
Gets the first token of the list.- Returns:
- the first token of the list
-
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
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
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
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
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
Creates a new list without the first token.- Returns:
- a new list without the first token
-
skipTail
Creates a new list without the last token.- Returns:
- a new list without the last token
-