Made it possible to reuse Tokenizer. Simplified Tokenizer building.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 11 Oct 2017 12:05:18 +0000 (15:05 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 11 Oct 2017 12:05:18 +0000 (15:05 +0300)
pom.xml
src/main/java/eu/svjatoslav/commons/string/tokenizer/Tokenizer.java

diff --git a/pom.xml b/pom.xml
index aa9ad66..4ac08fe 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>eu.svjatoslav</groupId>
     <artifactId>svjatoslavcommons</artifactId>
-    <version>1.6-SNAPSHOT</version>
+    <version>1.7-SNAPSHOT</version>
     <packaging>jar</packaging>
     <name>Svjatoslav Commons</name>
     <description>Collection many small but commonly useful functionalities</description>
index 8b396ed..a89677b 100755 (executable)
@@ -17,22 +17,32 @@ public class Tokenizer {
 
     final Stack<Integer> tokenIndexes = new Stack<>();
     private final List<Terminator> 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;