Class CharRange
- All Implemented Interfaces:
Serializable
,Iterable<Character>
A contiguous range of characters, optionally negated.
Instances are immutable.
#ThreadSafe#
- Since:
- 1.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final CharRange[]
Empty array.private final char
The last character, inclusive, in the range.private String
Cached toString.private final boolean
True if the range is everything except the characters specified.private static final long
Required for serialization support.private final char
The first character, inclusive, in the range. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CharRange
(char start, char end, boolean negated) Constructs aCharRange
over a set of characters, optionally negating the range. -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(char ch) Is the character specified contained in this range.boolean
Are all the characters of the passed in range contained in this range.boolean
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 aCharRange
over a single character.static CharRange
isIn
(char start, char end) Constructs aCharRange
over a set of characters.boolean
Is thisCharRange
negated.static CharRange
isNot
(char ch) Constructs a negatedCharRange
over a single character.static CharRange
isNotIn
(char start, char end) Constructs a negatedCharRange
over a set of characters.iterator()
Returns an iterator which can be used to walk through the characters described by this range.toString()
Gets a string representation of the character range.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDRequired for serialization support. Lang version 2.0.- See Also:
-
start
private final char startThe first character, inclusive, in the range. -
end
private final char endThe last character, inclusive, in the range. -
negated
private final boolean negatedTrue if the range is everything except the characters specified. -
iToString
Cached toString. -
EMPTY_ARRAY
Empty array.
-
-
Constructor Details
-
CharRange
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 ase-a
.- Parameters:
start
- first character, inclusive, in this rangeend
- last character, inclusive, in this rangenegated
- true to express everything except the range
-
-
Method Details
-
is
Constructs a
CharRange
over a single character.- Parameters:
ch
- only character in this range- Returns:
- the new CharRange object
- Since:
- 2.5
-
isNot
Constructs a negated
CharRange
over a single character.A negated range includes everything except that defined by the single character.
- Parameters:
ch
- only character in this range- Returns:
- the new CharRange object
- Since:
- 2.5
-
isIn
Constructs a
CharRange
over a set of characters.If start and end are in the wrong order, they are reversed. Thus
a-e
is the same ase-a
.- Parameters:
start
- first character, inclusive, in this rangeend
- last character, inclusive, in this range- Returns:
- the new CharRange object
- Since:
- 2.5
-
isNotIn
Constructs a negated
CharRange
over a set of characters.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 ase-a
.- Parameters:
start
- first character, inclusive, in this rangeend
- last character, inclusive, in this range- Returns:
- the new CharRange object
- Since:
- 2.5
-
getStart
public char getStart()Gets the start character for this character range.
- Returns:
- the start char (inclusive)
-
getEnd
public char getEnd()Gets the end character for this character range.
- Returns:
- the end char (inclusive)
-
isNegated
public boolean isNegated()Is this
CharRange
negated.A negated range includes everything except that defined by the start and end characters.
- Returns:
true
if negated
-
contains
public boolean contains(char ch) Is the character specified contained in this range.
- Parameters:
ch
- the character to check- Returns:
true
if this range contains the input character
-
contains
Are all the characters of the passed in range contained in this range.
- Parameters:
range
- the range to check against- Returns:
true
if this range entirely contains the input range- Throws:
IllegalArgumentException
- ifnull
input
-
equals
Compares two CharRange objects, returning true if they represent exactly the same range of characters defined in the same way.
-
hashCode
public int hashCode()Gets a hashCode compatible with the equals method.
-
toString
Gets a string representation of the character range.
-
iterator
Returns an iterator which can be used to walk through the characters described by this range.
#NotThreadSafe# the iterator is not thread-safe
-