You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2005/08/20 16:35:08 UTC

svn commit: r234032 - in /jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/StrTokenizer.java test/org/apache/commons/lang/text/StrTokenizerTest.java

Author: scolebourne
Date: Sat Aug 20 07:34:59 2005
New Revision: 234032

URL: http://svn.apache.org/viewcvs?rev=234032&view=rev
Log:
Enable chaining of methods

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java?rev=234032&r1=234031&r2=234032&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java Sat Aug 20 07:34:59 2005
@@ -450,10 +450,13 @@
      * Resets this tokenizer, forgetting all parsing and iteration already completed.
      * <p>
      * This method allows the same tokenizer to be reused for the same String.
+     *
+     * @return this, to enable chaining
      */
-    public void reset() {
+    public StrTokenizer reset() {
         tokenPos = 0;
         tokens = null;
+        return this;
     }
 
     /**
@@ -462,8 +465,9 @@
      * on multiple input lines.
      *
      * @param input  the new string to tokenize, null sets no text to parse
+     * @return this, to enable chaining
      */
-    public void reset(String input) {
+    public StrTokenizer reset(String input) {
         reset();
         text = input;
         if (input != null) {
@@ -471,6 +475,7 @@
         } else {
             chars = null;
         }
+        return this;
     }
 
     /**
@@ -482,11 +487,13 @@
      * passing in to this method.
      *
      * @param input  the new character array to tokenize, not cloned, null sets no text to parse
+     * @return this, to enable chaining
      */
-    public void reset(char[] input) {
+    public StrTokenizer reset(char[] input) {
         reset();
         text = null;
         chars = input;
+        return this;
     }
 
     // ListIterator
@@ -836,31 +843,35 @@
      * The delimitier is used to separate one token from another.
      *
      * @param delim  the delimiter matcher to use
+     * @return this, to enable chaining
      */
-    public void setDelimiterMatcher(StrMatcher delim) {
+    public StrTokenizer setDelimiterMatcher(StrMatcher delim) {
         if (delim == null) {
             this.delim = StrMatcher.noneMatcher();
         } else {
             this.delim = delim;
         }
+        return this;
     }
 
     /**
      * Sets the field delimiter character.
      *
      * @param delim  the delimiter character to use
+     * @return this, to enable chaining
      */
-    public void setDelimiterChar(char delim) {
-        setDelimiterMatcher(StrMatcher.charMatcher(delim));
+    public StrTokenizer setDelimiterChar(char delim) {
+        return setDelimiterMatcher(StrMatcher.charMatcher(delim));
     }
 
     /**
      * Sets the field delimiter string.
      *
      * @param delim  the delimiter string to use
+     * @return this, to enable chaining
      */
-    public void setDelimiterString(String delim) {
-        setDelimiterMatcher(StrMatcher.stringMatcher(delim));
+    public StrTokenizer setDelimiterString(String delim) {
+        return setDelimiterMatcher(StrMatcher.stringMatcher(delim));
     }
 
     // Quote
@@ -885,11 +896,13 @@
      * This enables delimiters to be entered as data.
      *
      * @param quote  the quote matcher to use, null ignored
+     * @return this, to enable chaining
      */
-    public void setQuoteMatcher(StrMatcher quote) {
+    public StrTokenizer setQuoteMatcher(StrMatcher quote) {
         if (quote != null) {
             this.quote = quote;
         }
+        return this;
     }
 
     /**
@@ -899,9 +912,10 @@
      * This enables delimiters to be entered as data.
      *
      * @param quote  the quote character to use
+     * @return this, to enable chaining
      */
-    public void setQuoteChar(char quote) {
-        setQuoteMatcher(StrMatcher.charMatcher(quote));
+    public StrTokenizer setQuoteChar(char quote) {
+        return setQuoteMatcher(StrMatcher.charMatcher(quote));
     }
 
     // Ignored
@@ -926,11 +940,13 @@
      * within a quoted region.
      *
      * @param ignored  the ignored matcher to use, null ignored
+     * @return this, to enable chaining
      */
-    public void setIgnoredMatcher(StrMatcher ignored) {
+    public StrTokenizer setIgnoredMatcher(StrMatcher ignored) {
         if (ignored != null) {
             this.ignored = ignored;
         }
+        return this;
     }
 
     /**
@@ -940,9 +956,10 @@
      * within a quoted region.
      *
      * @param ignored  the ignored character to use
+     * @return this, to enable chaining
      */
-    public void setIgnoredChar(char ignored) {
-        setIgnoredMatcher(StrMatcher.charMatcher(ignored));
+    public StrTokenizer setIgnoredChar(char ignored) {
+        return setIgnoredMatcher(StrMatcher.charMatcher(ignored));
     }
 
     // Trimmer
@@ -964,11 +981,13 @@
      * unquoted string.
      *
      * @param trimmer  the trimmer matcher to use, null ignored
+     * @return this, to enable chaining
      */
-    public void setTrimmerMatcher(StrMatcher trimmer) {
+    public StrTokenizer setTrimmerMatcher(StrMatcher trimmer) {
         if (trimmer != null) {
             this.trimmer = trimmer;
         }
+        return this;
     }
 
     //-----------------------------------------------------------------------
@@ -987,9 +1006,11 @@
      * The default for this property is false.
      *
      * @param emptyAsNull  whether empty tokens are returned as null
+     * @return this, to enable chaining
      */
-    public void setEmptyTokenAsNull(boolean emptyAsNull) {
+    public StrTokenizer setEmptyTokenAsNull(boolean emptyAsNull) {
         this.emptyAsNull = emptyAsNull;
+        return this;
     }
 
     //-----------------------------------------------------------------------
@@ -1008,9 +1029,11 @@
      * The default for this property is false.
      *
      * @param ignoreEmptyTokens  whether empty tokens are not returned
+     * @return this, to enable chaining
      */
-    public void setIgnoreEmptyTokens(boolean ignoreEmptyTokens) {
+    public StrTokenizer setIgnoreEmptyTokens(boolean ignoreEmptyTokens) {
         this.ignoreEmptyTokens = ignoreEmptyTokens;
+        return this;
     }
 
     //-----------------------------------------------------------------------
@@ -1035,7 +1058,7 @@
     public Object clone() {
         try {
             StrTokenizer cloned = (StrTokenizer) super.clone();
-            // chars[] does not need additional clone as it is treated as immutable
+            cloned.chars = (char[]) cloned.chars;
             cloned.reset();
             return cloned;
 

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java?rev=234032&r1=234031&r2=234032&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java Sat Aug 20 07:34:59 2005
@@ -349,6 +349,24 @@
     }
 
     //-----------------------------------------------------------------------
+    public void testChaining() {
+        StrTokenizer tok = new StrTokenizer();
+        assertEquals(tok, tok.reset());
+        assertEquals(tok, tok.reset(""));
+        assertEquals(tok, tok.reset(new char[0]));
+        assertEquals(tok, tok.setDelimiterChar(' '));
+        assertEquals(tok, tok.setDelimiterString(" "));
+        assertEquals(tok, tok.setDelimiterMatcher(null));
+        assertEquals(tok, tok.setQuoteChar(' '));
+        assertEquals(tok, tok.setQuoteMatcher(null));
+        assertEquals(tok, tok.setIgnoredChar(' '));
+        assertEquals(tok, tok.setIgnoredMatcher(null));
+        assertEquals(tok, tok.setTrimmerMatcher(null));
+        assertEquals(tok, tok.setEmptyTokenAsNull(false));
+        assertEquals(tok, tok.setIgnoreEmptyTokens(false));
+    }
+
+    //-----------------------------------------------------------------------
     public void testConstructor_String() {
         StrTokenizer tok = new StrTokenizer("a b");
         assertEquals("a", tok.next());



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org