From c98d0840bcd96c7c4dd79d6299f0429c45a476ee Mon Sep 17 00:00:00 2001 From: Niall Pemberton Date: Wed, 3 Feb 2010 12:22:27 +0000 Subject: [PATCH] LANG-454 implement Iterable and some javadoc changes git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@906028 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang3/CharRange.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/CharRange.java b/src/main/java/org/apache/commons/lang3/CharRange.java index 8cff4bf6f..e5b85432f 100644 --- a/src/main/java/org/apache/commons/lang3/CharRange.java +++ b/src/main/java/org/apache/commons/lang3/CharRange.java @@ -31,7 +31,7 @@ import java.util.NoSuchElementException; * @since 1.0 * @version $Id$ */ -public final class CharRange implements Serializable { +public final class CharRange implements Iterable, Serializable { /** * 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 */ - public Iterator iterator() { + public Iterator iterator() { return new CharacterIterator(this); } - static class CharacterIterator implements Iterator { - /** The currect character */ + /** + * Character {@link Iterator}. + */ + private static class CharacterIterator implements Iterator { + /** The current character */ private char current; private CharRange range; 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; hasNext = true; @@ -282,6 +290,9 @@ public final class CharRange implements Serializable { } } + /** + * Prepare the next character in the range. + */ private void prepareNext() { if (range.negated) { if (current == Character.MAX_VALUE) { @@ -316,7 +327,7 @@ public final class CharRange implements Serializable { * * @return Character for the next character */ - public Object next() { + public Character next() { if (hasNext == false) { throw new NoSuchElementException(); }