public static class CharRange.Builder
extends java.lang.Object
CharRange
s
Initially it contains an empty set of matching characters (CharRange.NONE).
Methods like addChars, addRange, exclude, etc. are called to add and remove characters
from the set, and then build()
is called to produce an immutable CharRange
object that matches characters in the set.
Constructor and Description |
---|
Builder()
Create a new Builder.
|
Modifier and Type | Method and Description |
---|---|
CharRange.Builder |
addChar(char c)
Add a character to the current set
|
CharRange.Builder |
addChars(java.lang.String chars)
Add characters to the current set
|
CharRange.Builder |
addRange(char first,
char last)
Add a range of characters to the current set
|
CharRange.Builder |
addRange(CharRange cr)
Add characters from another
CharRange |
CharRange |
build()
Produce a CharRange for the current set
|
CharRange.Builder |
clear()
Clears the current range.
|
CharRange.Builder |
exclude(CharRange cr)
Remove characters from another
CharRange |
CharRange.Builder |
expandCases()
Make the current range case independent.
|
CharRange.Builder |
intersect(CharRange cr)
Intersect with another
CharRange |
CharRange.Builder |
invert()
Invert the current set
|
public Builder()
It's usually a little more convenient to use CharRange.builder()
public CharRange.Builder clear()
After this call, build()
will return CharRange.NONE
public CharRange.Builder addChar(char c)
c
- This character will be added to the setpublic CharRange.Builder addChars(java.lang.String chars)
chars
- All characters in this string will be added to the setpublic CharRange.Builder addRange(char first, char last)
Adds all characters x such that first <= x and x <= last
first
- least-valued character to addlast
- greatest-valued character to addpublic CharRange.Builder addRange(CharRange cr)
CharRange
cr
- All characters matched by this CharRange will be added to the current setpublic final CharRange.Builder exclude(CharRange cr)
CharRange
This is implemented using invert()
and addRange(CharRange)
cr
- All characters matched by this CharRange will be removed from the current setpublic final CharRange.Builder intersect(CharRange cr)
CharRange
This is implemented by exclude(CharRange)
ing cr.getComplement()
cr
- All characters that are NOT matched by this CharRange will be removed from the current setpublic CharRange.Builder expandCases()
For every char c in the range, Character.toUpperCase(c) and Character.toLowerCase(c) are added.
public CharRange.Builder invert()
When this returns the current set will include only those characters that were NOT in the set before the call.
public CharRange build()
This method does not alter the current set in any way -- it may be further modified and used to produce more CharRange objects.