From a338e6716fcfe8a78692c4d803ec6a51d50b20a7 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 11 Oct 2017 15:05:18 +0300 Subject: [PATCH] Made it possible to reuse Tokenizer. Simplified Tokenizer building. --- pom.xml | 2 +- .../commons/string/tokenizer/Tokenizer.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index aa9ad66..4ac08fe 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 eu.svjatoslav svjatoslavcommons - 1.6-SNAPSHOT + 1.7-SNAPSHOT jar Svjatoslav Commons Collection many small but commonly useful functionalities 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 8b396ed..a89677b 100755 --- a/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java +++ b/src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java @@ -17,22 +17,32 @@ public class Tokenizer { final Stack tokenIndexes = new Stack<>(); private final List terminators = new ArrayList<>(); - private final String source; + private String source; private int currentIndex = 0; public Tokenizer(final String source) { this.source = source; } - public void addTerminator(final String startSequence, - final boolean ignoreTerminator) { + public Tokenizer(){} + + public Tokenizer setSource(String source){ + this.source = source; + currentIndex = 0; + return this; + } + + public Tokenizer addTerminator(final String startSequence, + final boolean ignoreTerminator) { terminators.add(new Terminator(startSequence, ignoreTerminator)); + return this; } - public void addTerminator(final String startSequence, - final String endSequence, final boolean ignoreTerminator) { + public Tokenizer addTerminator(final String startSequence, + final String endSequence, final boolean ignoreTerminator) { terminators.add(new Terminator(startSequence, endSequence, ignoreTerminator)); + return this; } public void expectNextToken(final String value) @@ -85,7 +95,7 @@ public class Tokenizer { } - public boolean probeNextToken(final String token) { + public boolean isNextToken(final String token) { if (token.equals(getNextToken().token)) return true; -- 2.20.1