Add toString

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@424611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2006-07-22 18:09:27 +00:00
parent 7917cc095b
commit d22e559db1
2 changed files with 33 additions and 4 deletions

View File

@ -1068,13 +1068,17 @@ public class StrTokenizer implements ListIterator, Cloneable {
* @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 @@ public class StrTokenizer implements ListIterator, Cloneable {
}
/**
* 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
@ -1102,4 +1106,18 @@ public class StrTokenizer implements ListIterator, Cloneable {
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();
}
}
}

View File

@ -536,6 +536,9 @@ public class StrTokenizerTest extends TestCase {
tok = new StrTokenizer(input.toCharArray());
assertEquals(input, tok.getContent());
tok = new StrTokenizer();
assertEquals(null, tok.getContent());
}
//-----------------------------------------------------------------------
@ -830,4 +833,12 @@ public class StrTokenizerTest extends TestCase {
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());
}
}