Top Description Inners Fields Constructors Methods
org.apache.commons.lang3

pack-priv final Class CharRange

extends Object
implements Iterable<Character>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Iterable
Imports
java.io.Serializable, java.util.Iterator, .NoSuchElementException, .Objects

A contiguous range of characters, optionally negated.

Instances are immutable.

#ThreadSafe#

Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
pack-priv static final CharRange[]
EMPTY_ARRAY

Empty array.

private final char
end

The last character, inclusive, in the range.

private transient String
iToString

Cached toString.

private final boolean
negated

True if the range is everything except the characters specified.

private static final long
serialVersionUID

Required for serialization support.

private final char
start

The first character, inclusive, in the range.

Constructor Summary

AccessConstructor and Description
private
CharRange(char
first character, inclusive, in this range
start
,
char
last character, inclusive, in this range
end
,
final boolean
true to express everything except the range
negated
)

Constructs a CharRange over a set of characters, optionally negating the range.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this range contains the input character
contains
(final char
the character to check
ch
)

Is the character specified contained in this range.

public boolean

Returns:

true if this range entirely contains the input range
contains
(final CharRange
the range to check against
range
)

Are all the characters of the passed in range contained in this range.

public boolean

Returns:

true if equal
equals
(final Object
the object to compare to
obj
)

Overrides java.lang.Object.equals.

Compares two CharRange objects, returning true if they represent exactly the same range of characters defined in the same way.

public char

Returns:

the end char (inclusive)
getEnd
()

Gets the end character for this character range.

public char

Returns:

the start char (inclusive)
getStart
()

Gets the start character for this character range.

public int

Returns:

a suitable hashCode
hashCode
()

Overrides java.lang.Object.hashCode.

Gets a hashCode compatible with the equals method.

public static CharRange

Returns:

the new CharRange object
is
(final char
only character in this range
ch
)

Constructs a CharRange over a single character.

public static CharRange

Returns:

the new CharRange object
isIn
(final char
first character, inclusive, in this range
start
,
final char
last character, inclusive, in this range
end
)

Constructs a CharRange over a set of characters.

public boolean

Returns:

true if negated
isNegated
()

Is this CharRange negated.

public static CharRange

Returns:

the new CharRange object
isNot
(final char
only character in this range
ch
)

Constructs a negated CharRange over a single character.

public static CharRange

Returns:

the new CharRange object
isNotIn
(final char
first character, inclusive, in this range
start
,
final char
last character, inclusive, in this range
end
)

Constructs a negated CharRange over a set of characters.

public Iterator<Character>

Returns:

an iterator to the chars represented by this range
iterator
()

Implements java.lang.Iterable.iterator.

Returns an iterator which can be used to walk through the characters described by this range.

public String

Returns:

string representation of this range
toString
()

Overrides java.lang.Object.toString.

Gets a string representation of the character range.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTY_ARRAYback to summary
pack-priv static final CharRange[] EMPTY_ARRAY

Empty array.

endback to summary
private final char end

The last character, inclusive, in the range.

iToStringback to summary
private transient String iToString

Cached toString.

negatedback to summary
private final boolean negated

True if the range is everything except the characters specified.

serialVersionUIDback to summary
private static final long serialVersionUID

Required for serialization support. Lang version 2.0.

See Also
java.io.Serializable
startback to summary
private final char start

The first character, inclusive, in the range.

Constructor Detail

CharRangeback to summary
private CharRange(char start, char end, final 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.

Parameters
start:char

first character, inclusive, in this range

end:char

last character, inclusive, in this range

negated:boolean

true to express everything except the range

Method Detail

containsback to summary
public boolean contains(final char ch)

Is the character specified contained in this range.

Parameters
ch:char

the character to check

Returns:boolean

true if this range contains the input character

containsback to summary
public boolean contains(final CharRange range)

Are all the characters of the passed in range contained in this range.

Parameters
range:CharRange

the range to check against

Returns:boolean

true if this range entirely contains the input range

Exceptions
NullPointerException:
if null input
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Compares two CharRange objects, returning true if they represent exactly the same range of characters defined in the same way.

Parameters
obj:Object

the object to compare to

Returns:boolean

true if equal

Annotations
@Override
getEndback to summary
public char getEnd()

Gets the end character for this character range.

Returns:char

the end char (inclusive)

getStartback to summary
public char getStart()

Gets the start character for this character range.

Returns:char

the start char (inclusive)

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Gets a hashCode compatible with the equals method.

Returns:int

a suitable hashCode

Annotations
@Override
isback to summary
public static CharRange is(final char ch)

Constructs a CharRange over a single character.

Parameters
ch:char

only character in this range

Returns:CharRange

the new CharRange object

Since
2.5
isInback to summary
public static CharRange isIn(final char start, final char end)

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 as e-a.

Parameters
start:char

first character, inclusive, in this range

end:char

last character, inclusive, in this range

Returns:CharRange

the new CharRange object

Since
2.5
isNegatedback to summary
public boolean isNegated()

Is this CharRange negated.

A negated range includes everything except that defined by the start and end characters.

Returns:boolean

true if negated

isNotback to summary
public static CharRange isNot(final char ch)

Constructs a negated CharRange over a single character.

A negated range includes everything except that defined by the single character.

Parameters
ch:char

only character in this range

Returns:CharRange

the new CharRange object

Since
2.5
isNotInback to summary
public static CharRange isNotIn(final char start, final char end)

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 as e-a.

Parameters
start:char

first character, inclusive, in this range

end:char

last character, inclusive, in this range

Returns:CharRange

the new CharRange object

Since
2.5
iteratorback to summary
public Iterator<Character> iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator which can be used to walk through the characters described by this range.

#NotThreadSafe# the iterator is not thread-safe

Returns:Iterator<Character>

an iterator to the chars represented by this range

Annotations
@Override
Since
2.5
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Gets a string representation of the character range.

Returns:String

string representation of this range

Annotations
@Override
org.apache.commons.lang3 back to summary

private final Class CharRange.CharacterIterator

extends Object
implements Iterator<Character>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Character Iterator.

#NotThreadSafe#

Field Summary

Modifier and TypeField and Description
private char
current

The current character

private boolean
private final CharRange

Constructor Summary

AccessConstructor and Description
private
CharacterIterator(final CharRange
The character range
r
)

Constructs a new iterator for the character range.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the iterator has yet to reach the character date
hasNext
()

Implements java.util.Iterator.hasNext.

Has the iterator not reached the end character yet?

public Character

Returns:

Character for the next character
next
()

Implements java.util.Iterator.next.

Returns the next character in the iteration

private void
prepareNext()

Prepares the next character in the range.

public void
remove()

Overrides default java.util.Iterator.remove.

Always throws UnsupportedOperationException.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

currentback to summary
private char current

The current character

hasNextback to summary
private boolean hasNext
rangeback to summary
private final CharRange range

Constructor Detail

CharacterIteratorback to summary
private CharacterIterator(final CharRange r)

Constructs a new iterator for the character range.

Parameters
r:CharRange

The character range

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Has the iterator not reached the end character yet?

Returns:boolean

true if the iterator has yet to reach the character date

Annotations
@Override
nextback to summary
public Character next()

Implements java.util.Iterator.next.

Returns the next character in the iteration

Returns:Character

Character for the next character

Annotations
@Override
prepareNextback to summary
private void prepareNext()

Prepares the next character in the range.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Always throws UnsupportedOperationException.

Annotations
@Override
Exceptions
UnsupportedOperationException:
Always thrown.
See Also
java.util.Iterator#remove()