Class CharRange
- All Implemented Interfaces:
Serializable,Iterable<Character>
Instances are immutable.
#ThreadSafe#
- Since:
- 1.0, 3.21.0
serialVersionUIDchanged from8270183163158333422Lto2L.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final CharRange[]Empty array.private final charThe last character, inclusive, in the range.private StringCached toString.private final booleanTrue if the range is everything except the characters specified.private static final longRequired for serialization support.private final charThe first character, inclusive, in the range. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(char ch) Is the character specified contained in this range.booleanAre all the characters of the passed in range contained in this range.booleanCompares two CharRange objects, returning true if they represent exactly the same range of characters defined in the same way.chargetEnd()Gets the end character for this character range.chargetStart()Gets the start character for this character range.inthashCode()Gets a hashCode compatible with the equals method.static CharRangeis(char ch) Constructs aCharRangeover a single character.(package private) booleanisEmpty()Tests whether this range denotes the empty set.private booleanisEndMax()static CharRangeisIn(char start, char end) Constructs aCharRangeover a set of characters.booleanTests whether thisCharRangeis negated.static CharRangeisNot(char ch) Constructs a negatedCharRangeover a single character.static CharRangeisNotIn(char start, char end) Constructs a negatedCharRangeover a set of characters.private booleaniterator()Returns an iterator which can be used to walk through the characters described by this range.private voidRe-asserts thestart <= endinvariant after default deserialization.toString()Gets a string representation of the character range.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDRequired for serialization support. Lang version 2.0.- Since:
- 3.21.0
serialVersionUIDchanged from8270183163158333422Lto 2L. - See Also:
-
EMPTY_ARRAY
Empty array. -
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.
-
-
Constructor Details
-
CharRange
private CharRange(char start, char end, boolean negated) Constructs aCharRangeover 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-eis the same ase-a.- Parameters:
start- first character, inclusive, in this range.end- last character, inclusive, in this range.negated- true to express everything except the range.
-
-
Method Details
-
is
Constructs aCharRangeover a single character.- Parameters:
ch- only character in this range.- Returns:
- The new CharRange object.
- Since:
- 2.5
-
isIn
Constructs aCharRangeover a set of characters.If start and end are in the wrong order, they are reversed. Thus
a-eis the same ase-a.- Parameters:
start- first character, inclusive, in this range.end- last character, inclusive, in this range.- Returns:
- The new CharRange object.
- Since:
- 2.5
-
isNot
Constructs a negatedCharRangeover 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
-
isNotIn
Constructs a negatedCharRangeover 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-eis the same ase-a.- Parameters:
start- first character, inclusive, in this range.end- last character, inclusive, in this range.- Returns:
- The new CharRange object.
- Since:
- 2.5
-
contains
public boolean contains(char ch) Is the character specified contained in this range.- Parameters:
ch- The character to check.- Returns:
trueif 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:
trueif this range entirely contains the input range.- Throws:
NullPointerException- Thrown ifnullinput.
-
equals
Compares two CharRange objects, returning true if they represent exactly the same range of characters defined in the same way. -
getEnd
public char getEnd()Gets the end character for this character range.- Returns:
- The end char (inclusive).
-
getStart
public char getStart()Gets the start character for this character range.- Returns:
- The start char (inclusive).
-
hashCode
public int hashCode()Gets a hashCode compatible with the equals method. -
isEmpty
boolean isEmpty()Tests whether this range denotes the empty set.A plain (non-negated) range always contains at least one character and is therefore never empty. A negated range is empty if and only if it excludes the entire character space, i.e. if it was created via
isNotIn(Character.MIN_VALUE, Character.MAX_VALUE).- Returns:
trueif this range contains no characters,falseotherwise.
-
isEndMax
private boolean isEndMax() -
isNegated
public boolean isNegated()Tests whether thisCharRangeis negated.A negated range includes everything except that defined by the start and end characters.
- Returns:
trueif negated.
-
isStartMin
private boolean isStartMin() -
iterator
Returns an iterator which can be used to walk through the characters described by this range.#NotThreadSafe# the iterator is not thread-safe
-
readObject
Re-asserts thestart <= endinvariant after default deserialization. The constructor reverses reversed endpoints, so a legitimately serialized instance always hasstart <= end; a stream that violates this did not come from the constructor and is rejected.- Parameters:
in- SeeSerializable.- Throws:
IOException- Thrown as described inSerializable.ClassNotFoundException- Thrown as described inSerializable.InvalidObjectException- Thrown ifstartis greater thanend.
-
toString
Gets a string representation of the character range.
-