@Override public Object clone() { CharArrayIterator clone = new CharArrayIterator(); clone.setText(array, start, length); clone.index = index; return clone; } }
public char setIndex(int position) { if (position < getBeginIndex() || position > getEndIndex()) throw new IllegalArgumentException("Illegal Position: " + position); index = start + position; return current(); }
public char current() { return (index == limit) ? DONE : jvmBugWorkaround(array[index]); }
public char previous() { if (--index < start) { index = start; return DONE; } else { return current(); } }
public void reset() throws IOException { iterator.setText(buffer, 0, 0); breaker.setText(iterator); length = usableLength = offset = index = 0; tokens.clear(); }
public char next() { if (++index >= limit) { index = limit; return DONE; } else { return current(); } }
/** * Refill the buffer, accumulating the offset and setting usableLength to the * last unambiguous break position * * @throws IOException */ private void refill() throws IOException { offset += usableLength; int leftover = length - usableLength; System.arraycopy(buffer, usableLength, buffer, 0, leftover); int requested = buffer.length - leftover; int returned = input.read(buffer, leftover, requested); length = returned < 0 ? leftover : returned + leftover; if (returned < requested) /* reader has been emptied, process the rest */ usableLength = length; else { /* still more data to be read, find a safe-stopping place */ usableLength = findSafeEnd(); if (usableLength < 0) usableLength = length; /* * more than IOBUFFER of text without breaks, * gonna possibly truncate tokens */ } iterator.setText(buffer, 0, Math.max(0, usableLength)); breaker.setText(iterator); }
public char first() { index = start; return current(); }
public char last() { index = (limit == start) ? limit : limit - 1; return current(); }