From 2082c4e93c58ae61eac0bdf7955e8996f6a19768 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 11 Oct 2017 18:19:47 +0300 Subject: [PATCH] Modernized syntax to java 8. --- .../commons/string/tokenizer/Tokenizer.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java index 01216d8..c4ca4d2 100755 --- a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java +++ b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java @@ -12,6 +12,7 @@ package eu.svjatoslav.commons.string.tokenizer; 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; @@ -112,20 +113,12 @@ public class Tokenizer { 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."); } -- 2.20.1