LANG-454 implement Iterable<Character> and some javadoc changes
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@906028 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
63ad5b063e
commit
c98d0840bc
|
@ -31,7 +31,7 @@ import java.util.NoSuchElementException;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public final class CharRange implements Serializable {
|
public final class CharRange implements Iterable<Character>, Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required for serialization support. Lang version 2.0.
|
* Required for serialization support. Lang version 2.0.
|
||||||
|
@ -251,18 +251,26 @@ public final class CharRange implements Serializable {
|
||||||
*
|
*
|
||||||
* @return an iterator to the chars represented by this range
|
* @return an iterator to the chars represented by this range
|
||||||
*/
|
*/
|
||||||
public Iterator iterator() {
|
public Iterator<Character> iterator() {
|
||||||
return new CharacterIterator(this);
|
return new CharacterIterator(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CharacterIterator implements Iterator {
|
/**
|
||||||
/** The currect character */
|
* Character {@link Iterator}.
|
||||||
|
*/
|
||||||
|
private static class CharacterIterator implements Iterator<Character> {
|
||||||
|
/** The current character */
|
||||||
private char current;
|
private char current;
|
||||||
|
|
||||||
private CharRange range;
|
private CharRange range;
|
||||||
private boolean hasNext;
|
private boolean hasNext;
|
||||||
|
|
||||||
public CharacterIterator(CharRange r) {
|
/**
|
||||||
|
* Construct a new iterator for the character range.
|
||||||
|
*
|
||||||
|
* @param r The character range
|
||||||
|
*/
|
||||||
|
private CharacterIterator(CharRange r) {
|
||||||
range = r;
|
range = r;
|
||||||
hasNext = true;
|
hasNext = true;
|
||||||
|
|
||||||
|
@ -282,6 +290,9 @@ public final class CharRange implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the next character in the range.
|
||||||
|
*/
|
||||||
private void prepareNext() {
|
private void prepareNext() {
|
||||||
if (range.negated) {
|
if (range.negated) {
|
||||||
if (current == Character.MAX_VALUE) {
|
if (current == Character.MAX_VALUE) {
|
||||||
|
@ -316,7 +327,7 @@ public final class CharRange implements Serializable {
|
||||||
*
|
*
|
||||||
* @return <code>Character</code> for the next character
|
* @return <code>Character</code> for the next character
|
||||||
*/
|
*/
|
||||||
public Object next() {
|
public Character next() {
|
||||||
if (hasNext == false) {
|
if (hasNext == false) {
|
||||||
throw new NoSuchElementException();
|
throw new NoSuchElementException();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue