import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
+import java.util.stream.Stream;
import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.DROP;
public boolean peekIsOneOf(String ... possibilities){
String nextToken = peekNextToken().token;
-
- for (String possibility : possibilities)
- if (possibility.equals(nextToken))
- return true;
-
- return false;
+ return Stream.of(possibilities).anyMatch(possibility -> possibility.equals(nextToken));
}
public void peekExpectNoneOf(String ... possibilities) throws InvalidSyntaxException {
- TokenizerMatch nextToken = peekNextToken();
-
- for (String possibility : possibilities)
- if (possibility.equals(nextToken))
- throw new InvalidSyntaxException("Not expected \"" + nextToken + "\" here.");
+ if (peekIsOneOf(possibilities))
+ throw new InvalidSyntaxException("Not expected \"" + peekNextToken().token + "\" here.");
}