commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r424596 - in /jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/StrTokenizer.java test/org/apache/commons/lang/text/StrTokenizerTest.java
Date Sat, 22 Jul 2006 16:08:26 GMT
Author: scolebourne
Date: Sat Jul 22 09:08:25 2006
New Revision: 424596

URL: http://svn.apache.org/viewvc?rev=424596&view=rev
Log:
Add method to get all tokens as a list as well as an array

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/viewvc/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrTokenizer.java?rev=424596&r1=424595&r2=424596&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 Jul 22 09:08:25 2006
@@ -446,13 +446,27 @@
     }
 
     /**
-     * Gets a copy of the full token list.
+     * Gets a copy of the full token list as an independent modifiable array.
      *
      * @return the tokens as a String array
      */
-    public String[] getAllTokens() {
+    public String[] getTokenArray() {
         tokenize();
         return (String[]) tokens.clone();
+    }
+
+    /**
+     * Gets a copy of the full token list as an independent modifiable list.
+     *
+     * @return the tokens as a String array
+     */
+    public List getTokenList() {
+        tokenize();
+        List list = new ArrayList(tokens.length);
+        for (int i = 0; i < tokens.length; i++) {
+            list.add(tokens[i]);
+        }
+        return list;
     }
 
     /**

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrTokenizerTest.java?rev=424596&r1=424595&r2=424596&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 Jul 22 09:08:25 2006
@@ -16,6 +16,8 @@
 
 package org.apache.commons.lang.text;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.NoSuchElementException;
 
 import junit.framework.Test;
@@ -70,7 +72,7 @@
         tok.setQuoteChar('"');
         tok.setIgnoredMatcher(StrMatcher.trimMatcher());
         tok.setIgnoreEmptyTokens(false);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", "", "", "",};
 
@@ -90,7 +92,7 @@
         tok.setQuoteChar('"');
         tok.setIgnoredMatcher(StrMatcher.noneMatcher());
         tok.setIgnoreEmptyTokens(false);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", "c ", "d;\"e", "f", " ", " ", "",};
 
@@ -110,7 +112,7 @@
         tok.setQuoteChar('"');
         tok.setIgnoredMatcher(StrMatcher.noneMatcher());
         tok.setIgnoreEmptyTokens(false);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", " c", "d;\"e", "f", " ", " ", "",};
 
@@ -130,7 +132,7 @@
         tok.setQuoteChar('"');
         tok.setIgnoredMatcher(StrMatcher.trimMatcher());
         tok.setIgnoreEmptyTokens(true);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", "c", "d;\"e", "f",};
 
@@ -151,7 +153,7 @@
         tok.setIgnoredMatcher(StrMatcher.trimMatcher());
         tok.setIgnoreEmptyTokens(false);
         tok.setEmptyTokenAsNull(true);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", "c", "d;\"e", "f", null, null, null,};
 
@@ -172,7 +174,7 @@
         tok.setIgnoredMatcher(StrMatcher.trimMatcher());
         tok.setIgnoreEmptyTokens(false);
         // tok.setTreatingEmptyAsNull(true);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", " c", "d;\"e", "f", null, null, null,};
 
@@ -206,7 +208,7 @@
         tok.setQuoteMatcher(StrMatcher.doubleQuoteMatcher());
         tok.setIgnoredMatcher(StrMatcher.noneMatcher());
         tok.setIgnoreEmptyTokens(false);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "", "", "b", "c", "d e", "f", "",};
 
@@ -226,7 +228,7 @@
         tok.setQuoteMatcher(StrMatcher.doubleQuoteMatcher());
         tok.setIgnoredMatcher(StrMatcher.noneMatcher());
         tok.setIgnoreEmptyTokens(true);
-        String tokens[] = tok.getAllTokens();
+        String tokens[] = tok.getTokenArray();
 
         String expected[] = new String[]{"a", "b", "c", "d e", "f",};
 
@@ -480,6 +482,17 @@
         assertEquals("bIGNOREcd", tok.next());
         assertEquals(null, tok.next());
         assertEquals(false, tok.hasNext());
+    }
+
+    //-----------------------------------------------------------------------
+    public void testListArray() {
+        String input = "a  b c";
+        StrTokenizer tok = new StrTokenizer(input);
+        String[] array = tok.getTokenArray();
+        List list = tok.getTokenList();
+        
+        assertEquals(Arrays.asList(array), list);
+        assertEquals(3, list.size());
     }
 
     //-----------------------------------------------------------------------



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


Mime
View raw message