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 2006/07/22 20:09:28 UTC
svn commit: r424611 - 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 Jul 22 11:09:27 2006
New Revision: 424611
URL: http://svn.apache.org/viewvc?rev=424611&view=rev
Log:
Add toString
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=424611&r1=424610&r2=424611&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 11:09:27 2006
@@ -1068,13 +1068,17 @@
* @return the string content being parsed
*/
public String getContent() {
+ if (chars == null) {
+ return null;
+ }
return new String(chars);
}
//-----------------------------------------------------------------------
/**
- * Creates a new instance of this Tokenizer. The new instance is reset so that it will be at the start of the token
- * list. If a {@link CloneNotSupportedException} is caught, return <code>null</code>.
+ * Creates a new instance of this Tokenizer. The new instance is reset so
+ * that it will be at the start of the token list.
+ * If a {@link CloneNotSupportedException} is caught, return <code>null</code>.
*
* @return a new instance of this Tokenizer which has been reset.
*/
@@ -1087,8 +1091,8 @@
}
/**
- * Creates a new instance of this Tokenizer. The new instance is reset so that it will be at the start of the token
- * list.
+ * Creates a new instance of this Tokenizer. The new instance is reset so that
+ * it will be at the start of the token list.
*
* @return a new instance of this Tokenizer which has been reset.
* @throws CloneNotSupportedException if there is a problem cloning
@@ -1100,6 +1104,20 @@
}
cloned.reset();
return cloned;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the String content that the tokenizer is parsing.
+ *
+ * @return the string content being parsed
+ */
+ public String toString() {
+ if (tokens == null) {
+ return "StrTokenizer[not tokenized yet]";
+ } else {
+ return "StrTokenizer" + getTokenList();
+ }
}
}
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=424611&r1=424610&r2=424611&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 11:09:27 2006
@@ -536,6 +536,9 @@
tok = new StrTokenizer(input.toCharArray());
assertEquals(input, tok.getContent());
+
+ tok = new StrTokenizer();
+ assertEquals(null, tok.getContent());
}
//-----------------------------------------------------------------------
@@ -828,6 +831,14 @@
assertEquals("c", tkn.next());
assertEquals("b", tkn.next());
assertEquals("a", tkn.next());
+ }
+
+ //-----------------------------------------------------------------------
+ public void testToString() {
+ StrTokenizer tkn = new StrTokenizer("a b c d e");
+ assertEquals("StrTokenizer[not tokenized yet]", tkn.toString());
+ tkn.next();
+ assertEquals("StrTokenizer[a, b, c, d, e]", tkn.toString());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org