Class CharRange
- java.lang.Object
-
- org.apache.commons.lang3.CharRange
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<java.lang.Character>
final class CharRange extends java.lang.Object implements java.lang.Iterable<java.lang.Character>, java.io.SerializableA contiguous range of characters, optionally negated.
Instances are immutable.
#ThreadSafe#
- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCharRange.CharacterIteratorCharacterIterator.
-
Field Summary
Fields Modifier and Type Field Description (package private) static CharRange[]EMPTY_ARRAYEmpty array.private charendThe last character, inclusive, in the range.private java.lang.StringiToStringCached toString.private booleannegatedTrue if the range is everything except the characters specified.private static longserialVersionUIDRequired for serialization support.private charstartThe first character, inclusive, in the range.
-
Constructor Summary
Constructors Modifier Constructor Description privateCharRange(char start, char end, boolean negated)Constructs aCharRangeover a set of characters, optionally negating the range.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(char ch)Is the character specified contained in this range.booleancontains(CharRange range)Are all the characters of the passed in range contained in this range.booleanequals(java.lang.Object obj)Compares 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.static CharRangeisIn(char start, char end)Constructs aCharRangeover a set of characters.booleanisNegated()Is thisCharRangenegated.static CharRangeisNot(char ch)Constructs a negatedCharRangeover a single character.static CharRangeisNotIn(char start, char end)Constructs a negatedCharRangeover 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.StringtoString()Gets a string representation of the character range.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Required for serialization support. Lang version 2.0.- See Also:
Serializable, Constant Field Values
-
start
private final char start
The first character, inclusive, in the range.
-
end
private final char end
The last character, inclusive, in the range.
-
negated
private final boolean negated
True if the range is everything except the characters specified.
-
iToString
private transient java.lang.String iToString
Cached toString.
-
EMPTY_ARRAY
static final CharRange[] EMPTY_ARRAY
Empty array.
-
-
Constructor Detail
-
CharRange
private CharRange(char start, char end, boolean negated)Constructs a
CharRangeover 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 rangeend- last character, inclusive, in this rangenegated- true to express everything except the range
-
-
Method Detail
-
is
public static CharRange is(char ch)
Constructs a
CharRangeover a single character.- Parameters:
ch- only character in this range- Returns:
- the new CharRange object
- Since:
- 2.5
-
isNot
public static CharRange isNot(char ch)
Constructs a negated
CharRangeover 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
public static CharRange isIn(char start, char end)
Constructs a
CharRangeover 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 rangeend- last character, inclusive, in this range- Returns:
- the new CharRange object
- Since:
- 2.5
-
isNotIn
public static CharRange isNotIn(char start, char end)
Constructs a negated
CharRangeover 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 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
CharRangenegated.A negated range includes everything except that defined by the start and end characters.
- Returns:
trueif negated
-
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
public boolean contains(CharRange range)
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:
java.lang.IllegalArgumentException- ifnullinput
-
equals
public 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.
- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare to- Returns:
- true if equal
-
hashCode
public int hashCode()
Gets a hashCode compatible with the equals method.
- Overrides:
hashCodein classjava.lang.Object- Returns:
- a suitable hashCode
-
toString
public java.lang.String toString()
Gets a string representation of the character range.
- Overrides:
toStringin classjava.lang.Object- Returns:
- string representation of this range
-
iterator
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
- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Character>- Returns:
- an iterator to the chars represented by this range
- Since:
- 2.5
-
-