import org.eclipse.jface.text.Assert;
-
/**
- * A <code>CharSequence</code> based implementation of <code>CharacterIterator</code>.
+ * A <code>CharSequence</code> based implementation of
+ * <code>CharacterIterator</code>.
*
* @since 3.0
*/
public class SequenceCharacterIterator implements CharacterIterator {
- private int fIndex= -1;
+ private int fIndex = -1;
+
private final CharSequence fSequence;
+
private final int fFirst;
+
private final int fLast;
-
+
private void invariant() {
Assert.isTrue(fIndex >= fFirst);
Assert.isTrue(fIndex <= fLast);
}
-
+
/**
* Creates an iterator for the entire sequence.
*
- * @param sequence the sequence backing this iterator
+ * @param sequence
+ * the sequence backing this iterator
*/
public SequenceCharacterIterator(CharSequence sequence) {
this(sequence, 0);
}
-
+
/**
* Creates an iterator.
*
- * @param sequence the sequence backing this iterator
- * @param first the first character to consider
- * @throws IllegalArgumentException if the indices are out of bounds
+ * @param sequence
+ * the sequence backing this iterator
+ * @param first
+ * the first character to consider
+ * @throws IllegalArgumentException
+ * if the indices are out of bounds
*/
- public SequenceCharacterIterator(CharSequence sequence, int first) throws IllegalArgumentException {
+ public SequenceCharacterIterator(CharSequence sequence, int first)
+ throws IllegalArgumentException {
this(sequence, first, sequence.length());
}
/**
* Creates an iterator.
*
- * @param sequence the sequence backing this iterator
- * @param first the first character to consider
- * @param last the last character index to consider
- * @throws IllegalArgumentException if the indices are out of bounds
+ * @param sequence
+ * the sequence backing this iterator
+ * @param first
+ * the first character to consider
+ * @param last
+ * the last character index to consider
+ * @throws IllegalArgumentException
+ * if the indices are out of bounds
*/
- public SequenceCharacterIterator(CharSequence sequence, int first, int last) throws IllegalArgumentException {
+ public SequenceCharacterIterator(CharSequence sequence, int first, int last)
+ throws IllegalArgumentException {
if (sequence == null)
throw new NullPointerException();
if (first < 0 || first > last)
throw new IllegalArgumentException();
if (last > sequence.length())
throw new IllegalArgumentException();
- fSequence= sequence;
- fFirst= first;
- fLast= last;
- fIndex= first;
+ fSequence = sequence;
+ fFirst = first;
+ fLast = last;
+ fIndex = first;
invariant();
}
*/
public char setIndex(int position) {
if (position >= getBeginIndex() && position <= getEndIndex())
- fIndex= position;
+ fIndex = position;
else
throw new IllegalArgumentException();
-
+
invariant();
return current();
}