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:
parent
7917cc095b
commit
d22e559db1
|
@ -1068,13 +1068,17 @@ public class StrTokenizer implements ListIterator, Cloneable {
|
||||||
* @return the string content being parsed
|
* @return the string content being parsed
|
||||||
*/
|
*/
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
|
if (chars == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new String(chars);
|
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
|
* Creates a new instance of this Tokenizer. The new instance is reset so
|
||||||
* list. If a {@link CloneNotSupportedException} is caught, return <code>null</code>.
|
* 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.
|
* @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
|
* Creates a new instance of this Tokenizer. The new instance is reset so that
|
||||||
* list.
|
* it will be at the start of the token list.
|
||||||
*
|
*
|
||||||
* @return a new instance of this Tokenizer which has been reset.
|
* @return a new instance of this Tokenizer which has been reset.
|
||||||
* @throws CloneNotSupportedException if there is a problem cloning
|
* @throws CloneNotSupportedException if there is a problem cloning
|
||||||
|
@ -1102,4 +1106,18 @@ public class StrTokenizer implements ListIterator, Cloneable {
|
||||||
return cloned;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,6 +536,9 @@ public class StrTokenizerTest extends TestCase {
|
||||||
|
|
||||||
tok = new StrTokenizer(input.toCharArray());
|
tok = new StrTokenizer(input.toCharArray());
|
||||||
assertEquals(input, tok.getContent());
|
assertEquals(input, tok.getContent());
|
||||||
|
|
||||||
|
tok = new StrTokenizer();
|
||||||
|
assertEquals(null, tok.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -830,4 +833,12 @@ public class StrTokenizerTest extends TestCase {
|
||||||
assertEquals("a", 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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue