final class CharRange
extends java.lang.Object
implements java.lang.Iterable<java.lang.Character>, java.io.Serializable
A contiguous range of characters, optionally negated.
Instances are immutable.
#ThreadSafe#
Modifier and Type | Class and Description |
---|---|
private static class |
CharRange.CharacterIterator
Character
Iterator . |
Modifier and Type | Field and Description |
---|---|
private char |
end
The last character, inclusive, in the range.
|
private java.lang.String |
iToString
Cached toString.
|
private boolean |
negated
True if the range is everything except the characters specified.
|
private static long |
serialVersionUID
Required for serialization support.
|
private char |
start
The first character, inclusive, in the range.
|
Modifier | Constructor and Description |
---|---|
private |
CharRange(char start,
char end,
boolean negated)
Constructs a
CharRange over a set of characters,
optionally negating the range. |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(char ch)
Is the character specified contained in this range.
|
boolean |
contains(CharRange range)
Are all the characters of the passed in range contained in
this range.
|
boolean |
equals(java.lang.Object obj)
Compares two CharRange objects, returning true if they represent
exactly the same range of characters defined in the same way.
|
char |
getEnd()
Gets the end character for this character range.
|
char |
getStart()
Gets the start character for this character range.
|
int |
hashCode()
Gets a hashCode compatible with the equals method.
|
static CharRange |
is(char ch)
Constructs a
CharRange over a single character. |
static CharRange |
isIn(char start,
char end)
Constructs a
CharRange over a set of characters. |
boolean |
isNegated()
Is this
CharRange negated. |
static CharRange |
isNot(char ch)
Constructs a negated
CharRange over a single character. |
static CharRange |
isNotIn(char start,
char end)
Constructs a negated
CharRange over a set of characters. |
java.util.Iterator<java.lang.Character> |
iterator()
Returns an iterator which can be used to walk through the characters described by this range.
|
java.lang.String |
toString()
Gets a string representation of the character range.
|
private static final long serialVersionUID
Serializable
,
Constant Field Valuesprivate final char start
private final char end
private final boolean negated
private transient java.lang.String iToString
private CharRange(char start, char end, boolean negated)
Constructs a CharRange
over a set of characters,
optionally negating the range.
A negated range includes everything except that defined by the start and end characters.
If start and end are in the wrong order, they are reversed.
Thus a-e
is the same as e-a
.
start
- first character, inclusive, in this rangeend
- last character, inclusive, in this rangenegated
- true to express everything except the rangepublic static CharRange is(char ch)
Constructs a CharRange
over a single character.
ch
- only character in this rangeCharRange(char, char, boolean)
public static CharRange isNot(char ch)
Constructs a negated CharRange
over a single character.
ch
- only character in this rangeCharRange(char, char, boolean)
public static CharRange isIn(char start, char end)
Constructs a CharRange
over a set of characters.
start
- first character, inclusive, in this rangeend
- last character, inclusive, in this rangeCharRange(char, char, boolean)
public static CharRange isNotIn(char start, char end)
Constructs a negated CharRange
over a set of characters.
start
- first character, inclusive, in this rangeend
- last character, inclusive, in this rangeCharRange(char, char, boolean)
public char getStart()
Gets the start character for this character range.
public char getEnd()
Gets the end character for this character range.
public boolean isNegated()
Is this CharRange
negated.
A negated range includes everything except that defined by the start and end characters.
true
if negatedpublic boolean contains(char ch)
Is the character specified contained in this range.
ch
- the character to checktrue
if this range contains the input characterpublic boolean contains(CharRange range)
Are all the characters of the passed in range contained in this range.
range
- the range to check againsttrue
if this range entirely contains the input rangejava.lang.IllegalArgumentException
- if null
inputpublic boolean equals(java.lang.Object obj)
Compares two CharRange objects, returning true if they represent exactly the same range of characters defined in the same way.
equals
in class java.lang.Object
obj
- the object to compare topublic int hashCode()
Gets a hashCode compatible with the equals method.
hashCode
in class java.lang.Object
public java.lang.String toString()
Gets a string representation of the character range.
toString
in class java.lang.Object
public java.util.Iterator<java.lang.Character> iterator()
Returns an iterator which can be used to walk through the characters described by this range.
#NotThreadSafe# the iterator is not thread-safe
iterator
in interface java.lang.Iterable<java.lang.Character>