@Deprecated
public class StrTokenizer
extends java.lang.Object
implements java.util.ListIterator<java.lang.String>, java.lang.Cloneable
This class can split a String into many smaller strings. It aims
to do a similar job to StringTokenizer
,
however it offers much more control and flexibility including implementing
the ListIterator
interface. By default, it is set up
like StringTokenizer
.
The input String is split into a number of tokens. Each token is separated from the next String by a delimiter. One or more delimiter characters must be specified.
Each token may be surrounded by quotes. The quote matcher specifies the quote character(s). A quote may be escaped within a quoted section by duplicating itself.
Between each token and the delimiter are potentially characters that need trimming. The trimmer matcher specifies these characters. One usage might be to trim whitespace characters.
At any point outside the quotes there might potentially be invalid characters. The ignored matcher specifies these characters to be removed. One usage might be to remove new line characters.
Empty tokens may be removed or returned as null.
"a,b,c" - Three tokens "a","b","c" (comma delimiter) " a, b , c " - Three tokens "a","b","c" (default CSV processing trims whitespace) "a, ", b ,", c" - Three tokens "a, " , " b ", ", c" (quoted text untouched)
Property | Type | Default |
---|---|---|
delim | CharSetMatcher | { \t\n\r\f} |
quote | NoneMatcher | {} |
ignore | NoneMatcher | {} |
emptyTokenAsNull | boolean | false |
ignoreEmptyTokens | boolean | true |
Constructor and Description |
---|
StrTokenizer()
Deprecated.
Constructs a tokenizer splitting on space, tab, newline and formfeed
as per StringTokenizer, but with no text to tokenize.
|
StrTokenizer(char[] input)
Deprecated.
Constructs a tokenizer splitting on space, tab, newline and formfeed
as per StringTokenizer.
|
StrTokenizer(char[] input,
char delim)
Deprecated.
Constructs a tokenizer splitting on the specified character.
|
StrTokenizer(char[] input,
char delim,
char quote)
Deprecated.
Constructs a tokenizer splitting on the specified delimiter character
and handling quotes using the specified quote character.
|
StrTokenizer(char[] input,
java.lang.String delim)
Deprecated.
Constructs a tokenizer splitting on the specified string.
|
StrTokenizer(char[] input,
StrMatcher delim)
Deprecated.
Constructs a tokenizer splitting using the specified delimiter matcher.
|
StrTokenizer(char[] input,
StrMatcher delim,
StrMatcher quote)
Deprecated.
Constructs a tokenizer splitting using the specified delimiter matcher
and handling quotes using the specified quote matcher.
|
StrTokenizer(java.lang.String input)
Deprecated.
Constructs a tokenizer splitting on space, tab, newline and formfeed
as per StringTokenizer.
|
StrTokenizer(java.lang.String input,
char delim)
Deprecated.
Constructs a tokenizer splitting on the specified delimiter character.
|
StrTokenizer(java.lang.String input,
char delim,
char quote)
Deprecated.
Constructs a tokenizer splitting on the specified delimiter character
and handling quotes using the specified quote character.
|
StrTokenizer(java.lang.String input,
java.lang.String delim)
Deprecated.
Constructs a tokenizer splitting on the specified delimiter string.
|
StrTokenizer(java.lang.String input,
StrMatcher delim)
Deprecated.
Constructs a tokenizer splitting using the specified delimiter matcher.
|
StrTokenizer(java.lang.String input,
StrMatcher delim,
StrMatcher quote)
Deprecated.
Constructs a tokenizer splitting using the specified delimiter matcher
and handling quotes using the specified quote matcher.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String obj)
Deprecated.
Unsupported ListIterator operation.
|
java.lang.Object |
clone()
Deprecated.
Creates a new instance of this Tokenizer.
|
java.lang.String |
getContent()
Deprecated.
Gets the String content that the tokenizer is parsing.
|
static StrTokenizer |
getCSVInstance()
Deprecated.
Gets a new tokenizer instance which parses Comma Separated Value strings
initializing it with the given input.
|
static StrTokenizer |
getCSVInstance(char[] input)
Deprecated.
Gets a new tokenizer instance which parses Comma Separated Value strings
initializing it with the given input.
|
static StrTokenizer |
getCSVInstance(java.lang.String input)
Deprecated.
Gets a new tokenizer instance which parses Comma Separated Value strings
initializing it with the given input.
|
StrMatcher |
getDelimiterMatcher()
Deprecated.
Gets the field delimiter matcher.
|
StrMatcher |
getIgnoredMatcher()
Deprecated.
Gets the ignored character matcher.
|
StrMatcher |
getQuoteMatcher()
Deprecated.
Gets the quote matcher currently in use.
|
java.lang.String[] |
getTokenArray()
Deprecated.
Gets a copy of the full token list as an independent modifiable array.
|
java.util.List<java.lang.String> |
getTokenList()
Deprecated.
Gets a copy of the full token list as an independent modifiable list.
|
StrMatcher |
getTrimmerMatcher()
Deprecated.
Gets the trimmer character matcher.
|
static StrTokenizer |
getTSVInstance()
Deprecated.
Gets a new tokenizer instance which parses Tab Separated Value strings.
|
static StrTokenizer |
getTSVInstance(char[] input)
Deprecated.
Gets a new tokenizer instance which parses Tab Separated Value strings.
|
static StrTokenizer |
getTSVInstance(java.lang.String input)
Deprecated.
Gets a new tokenizer instance which parses Tab Separated Value strings.
|
boolean |
hasNext()
Deprecated.
Checks whether there are any more tokens.
|
boolean |
hasPrevious()
Deprecated.
Checks whether there are any previous tokens that can be iterated to.
|
boolean |
isEmptyTokenAsNull()
Deprecated.
Gets whether the tokenizer currently returns empty tokens as null.
|
boolean |
isIgnoreEmptyTokens()
Deprecated.
Gets whether the tokenizer currently ignores empty tokens.
|
java.lang.String |
next()
Deprecated.
Gets the next token.
|
int |
nextIndex()
Deprecated.
Gets the index of the next token to return.
|
java.lang.String |
nextToken()
Deprecated.
Gets the next token from the String.
|
java.lang.String |
previous()
Deprecated.
Gets the token previous to the last returned token.
|
int |
previousIndex()
Deprecated.
Gets the index of the previous token.
|
java.lang.String |
previousToken()
Deprecated.
Gets the previous token from the String.
|
void |
remove()
Deprecated.
Unsupported ListIterator operation.
|
StrTokenizer |
reset()
Deprecated.
Resets this tokenizer, forgetting all parsing and iteration already completed.
|
StrTokenizer |
reset(char[] input)
Deprecated.
Reset this tokenizer, giving it a new input string to parse.
|
StrTokenizer |
reset(java.lang.String input)
Deprecated.
Reset this tokenizer, giving it a new input string to parse.
|
void |
set(java.lang.String obj)
Deprecated.
Unsupported ListIterator operation.
|
StrTokenizer |
setDelimiterChar(char delim)
Deprecated.
Sets the field delimiter character.
|
StrTokenizer |
setDelimiterMatcher(StrMatcher delim)
Deprecated.
Sets the field delimiter matcher.
|
StrTokenizer |
setDelimiterString(java.lang.String delim)
Deprecated.
Sets the field delimiter string.
|
StrTokenizer |
setEmptyTokenAsNull(boolean emptyAsNull)
Deprecated.
Sets whether the tokenizer should return empty tokens as null.
|
StrTokenizer |
setIgnoredChar(char ignored)
Deprecated.
Set the character to ignore.
|
StrTokenizer |
setIgnoredMatcher(StrMatcher ignored)
Deprecated.
Set the matcher for characters to ignore.
|
StrTokenizer |
setIgnoreEmptyTokens(boolean ignoreEmptyTokens)
Deprecated.
Sets whether the tokenizer should ignore and not return empty tokens.
|
StrTokenizer |
setQuoteChar(char quote)
Deprecated.
Sets the quote character to use.
|
StrTokenizer |
setQuoteMatcher(StrMatcher quote)
Deprecated.
Set the quote matcher to use.
|
StrTokenizer |
setTrimmerMatcher(StrMatcher trimmer)
Deprecated.
Sets the matcher for characters to trim.
|
int |
size()
Deprecated.
Gets the number of tokens found in the String.
|
java.lang.String |
toString()
Deprecated.
Gets the String content that the tokenizer is parsing.
|
public StrTokenizer()
This constructor is normally used with reset(String)
.
public StrTokenizer(java.lang.String input)
input
- the string which is to be parsedpublic StrTokenizer(java.lang.String input, char delim)
input
- the string which is to be parseddelim
- the field delimiter characterpublic StrTokenizer(java.lang.String input, java.lang.String delim)
input
- the string which is to be parseddelim
- the field delimiter stringpublic StrTokenizer(java.lang.String input, StrMatcher delim)
input
- the string which is to be parseddelim
- the field delimiter matcherpublic StrTokenizer(java.lang.String input, char delim, char quote)
input
- the string which is to be parseddelim
- the field delimiter characterquote
- the field quoted string characterpublic StrTokenizer(java.lang.String input, StrMatcher delim, StrMatcher quote)
input
- the string which is to be parseddelim
- the field delimiter matcherquote
- the field quoted string matcherpublic StrTokenizer(char[] input)
input
- the string which is to be parsed, not clonedpublic StrTokenizer(char[] input, char delim)
input
- the string which is to be parsed, not cloneddelim
- the field delimiter characterpublic StrTokenizer(char[] input, java.lang.String delim)
input
- the string which is to be parsed, not cloneddelim
- the field delimiter stringpublic StrTokenizer(char[] input, StrMatcher delim)
input
- the string which is to be parsed, not cloneddelim
- the field delimiter matcherpublic StrTokenizer(char[] input, char delim, char quote)
input
- the string which is to be parsed, not cloneddelim
- the field delimiter characterquote
- the field quoted string characterpublic StrTokenizer(char[] input, StrMatcher delim, StrMatcher quote)
input
- the string which is to be parsed, not cloneddelim
- the field delimiter characterquote
- the field quoted string characterpublic static StrTokenizer getCSVInstance()
You must call a "reset" method to set the string which you want to parse.
public static StrTokenizer getCSVInstance(java.lang.String input)
input
- the text to parsepublic static StrTokenizer getCSVInstance(char[] input)
input
- the text to parsepublic static StrTokenizer getTSVInstance()
You must call a "reset" method to set the string which you want to parse.
public static StrTokenizer getTSVInstance(java.lang.String input)
input
- the string to parsepublic static StrTokenizer getTSVInstance(char[] input)
input
- the string to parsepublic int size()
public java.lang.String nextToken()
next()
except it returns null rather than
throwing NoSuchElementException
when no tokens remain.public java.lang.String previousToken()
public java.lang.String[] getTokenArray()
public java.util.List<java.lang.String> getTokenList()
public StrTokenizer reset()
This method allows the same tokenizer to be reused for the same String.
public StrTokenizer reset(java.lang.String input)
input
- the new string to tokenize, null sets no text to parsepublic StrTokenizer reset(char[] input)
input
- the new character array to tokenize, not cloned, null sets no text to parsepublic boolean hasNext()
hasNext
in interface java.util.Iterator<java.lang.String>
hasNext
in interface java.util.ListIterator<java.lang.String>
public java.lang.String next()
next
in interface java.util.Iterator<java.lang.String>
next
in interface java.util.ListIterator<java.lang.String>
java.util.NoSuchElementException
- if there are no more elementspublic int nextIndex()
nextIndex
in interface java.util.ListIterator<java.lang.String>
public boolean hasPrevious()
hasPrevious
in interface java.util.ListIterator<java.lang.String>
public java.lang.String previous()
previous
in interface java.util.ListIterator<java.lang.String>
public int previousIndex()
previousIndex
in interface java.util.ListIterator<java.lang.String>
public void remove()
remove
in interface java.util.Iterator<java.lang.String>
remove
in interface java.util.ListIterator<java.lang.String>
java.lang.UnsupportedOperationException
- alwayspublic void set(java.lang.String obj)
set
in interface java.util.ListIterator<java.lang.String>
obj
- this parameter ignored.java.lang.UnsupportedOperationException
- alwayspublic void add(java.lang.String obj)
add
in interface java.util.ListIterator<java.lang.String>
obj
- this parameter ignored.java.lang.UnsupportedOperationException
- alwayspublic StrMatcher getDelimiterMatcher()
public StrTokenizer setDelimiterMatcher(StrMatcher delim)
The delimiter is used to separate one token from another.
delim
- the delimiter matcher to usepublic StrTokenizer setDelimiterChar(char delim)
delim
- the delimiter character to usepublic StrTokenizer setDelimiterString(java.lang.String delim)
delim
- the delimiter string to usepublic StrMatcher getQuoteMatcher()
The quote character is used to wrap data between the tokens. This enables delimiters to be entered as data. The default value is '"' (double quote).
public StrTokenizer setQuoteMatcher(StrMatcher quote)
The quote character is used to wrap data between the tokens. This enables delimiters to be entered as data.
quote
- the quote matcher to use, null ignoredpublic StrTokenizer setQuoteChar(char quote)
The quote character is used to wrap data between the tokens. This enables delimiters to be entered as data.
quote
- the quote character to usepublic StrMatcher getIgnoredMatcher()
These characters are ignored when parsing the String, unless they are within a quoted region. The default value is not to ignore anything.
public StrTokenizer setIgnoredMatcher(StrMatcher ignored)
These characters are ignored when parsing the String, unless they are within a quoted region.
ignored
- the ignored matcher to use, null ignoredpublic StrTokenizer setIgnoredChar(char ignored)
This character is ignored when parsing the String, unless it is within a quoted region.
ignored
- the ignored character to usepublic StrMatcher getTrimmerMatcher()
These characters are trimmed off on each side of the delimiter until the token or quote is found. The default value is not to trim anything.
public StrTokenizer setTrimmerMatcher(StrMatcher trimmer)
These characters are trimmed off on each side of the delimiter until the token or quote is found.
trimmer
- the trimmer matcher to use, null ignoredpublic boolean isEmptyTokenAsNull()
public StrTokenizer setEmptyTokenAsNull(boolean emptyAsNull)
emptyAsNull
- whether empty tokens are returned as nullpublic boolean isIgnoreEmptyTokens()
public StrTokenizer setIgnoreEmptyTokens(boolean ignoreEmptyTokens)
ignoreEmptyTokens
- whether empty tokens are not returnedpublic java.lang.String getContent()
public java.lang.Object clone()
CloneNotSupportedException
is caught, return null
.clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"