2020-11-16 02:55:33 +01:00
|
|
|
package speiger.src.collections.PACKAGE.utils;
|
|
|
|
|
2020-11-28 15:05:28 +01:00
|
|
|
import java.util.Iterator;
|
2020-11-16 02:55:33 +01:00
|
|
|
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
2020-12-01 02:43:13 +01:00
|
|
|
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
2020-12-20 05:45:16 +01:00
|
|
|
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
2020-11-16 02:55:33 +01:00
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Helper class for Iterators
|
|
|
|
*/
|
2020-11-16 02:55:33 +01:00
|
|
|
public class ITERATORS
|
|
|
|
{
|
2020-12-01 02:43:13 +01:00
|
|
|
public static final EmptyIterator NO_GENERIC_TYPE EMPTY = new EmptyIteratorBRACES();
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Immutable EmptyIterator instance that is automatically casted.
|
|
|
|
* @return an empty iterator
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES EmptyIterator KEY_GENERIC_TYPE emptyIterator() {
|
2020-12-01 02:43:13 +01:00
|
|
|
#if TYPE_OBJECT
|
|
|
|
return (EmptyIterator<KEY_TYPE>)EMPTY;
|
|
|
|
#else
|
|
|
|
return EMPTY;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-01-28 20:42:29 +01:00
|
|
|
public static GENERIC_KEY_BRACES BI_ITERATOR KEY_GENERIC_TYPE invert(BI_ITERATOR KEY_GENERIC_TYPE it) {
|
|
|
|
return new BI_ITERATOR KEY_GENERIC_TYPE() {
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() { return it.hasPrevious(); }
|
|
|
|
@Override
|
|
|
|
public boolean hasPrevious() { return it.hasNext(); }
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
|
|
|
@Override
|
|
|
|
public void remove() { it.remove(); }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE invert(LIST_ITERATOR KEY_GENERIC_TYPE it) {
|
|
|
|
return new LIST_ITERATOR KEY_GENERIC_TYPE() {
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() { return it.PREVIOUS(); }
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() { return it.hasPrevious(); }
|
|
|
|
@Override
|
|
|
|
public boolean hasPrevious() { return it.hasNext(); }
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE PREVIOUS() { return it.NEXT(); }
|
|
|
|
@Override
|
|
|
|
public void remove() { it.remove(); }
|
|
|
|
@Override
|
|
|
|
public int nextIndex() { return it.previousIndex(); }
|
|
|
|
@Override
|
|
|
|
public int previousIndex() { return it.nextIndex(); }
|
|
|
|
@Override
|
|
|
|
public void set(KEY_TYPE e) { it.set(e); }
|
|
|
|
@Override
|
|
|
|
public void add(KEY_TYPE e) { it.add(e); }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Immutable Iterator instance based on the instance given.
|
2021-04-22 23:02:04 +02:00
|
|
|
* @param iterator that should be made immutable/unmodifyable
|
2020-12-06 09:32:22 +01:00
|
|
|
* @return a unmodifiable iterator wrapper. If the Iterator already a unmodifyable wrapper then it just returns itself.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE unmodifiable(ITERATOR KEY_GENERIC_TYPE iterator) {
|
2020-12-06 09:32:22 +01:00
|
|
|
return iterator instanceof UnmodifiableIterator ? iterator : new UnmodifiableIteratorBRACES(iterator);
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES BI_ITERATOR KEY_GENERIC_TYPE unmodifiable(BI_ITERATOR KEY_GENERIC_TYPE iterator) {
|
2020-12-20 05:45:16 +01:00
|
|
|
return iterator instanceof UnmodifiableBiIterator ? iterator : new UnmodifiableBiIteratorBRACES(iterator);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Immutable ListIterator instance based on the instance given.
|
2021-04-22 23:02:04 +02:00
|
|
|
* @param iterator that should be made immutable/unmodifyable
|
2020-12-06 09:32:22 +01:00
|
|
|
* @return a unmodifiable listiterator wrapper. If the ListIterator already a unmodifyable wrapper then it just returns itself.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES LIST_ITERATOR KEY_GENERIC_TYPE unmodifiable(LIST_ITERATOR KEY_GENERIC_TYPE iterator) {
|
2020-12-06 09:32:22 +01:00
|
|
|
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
2020-12-13 20:14:22 +01:00
|
|
|
#if !TYPE_OBJECT
|
|
|
|
public static ITERATOR wrap(Iterator<CLASS_TYPE> iterator) {
|
|
|
|
return iterator instanceof ITERATOR ? (ITERATOR)iterator : new IteratorWrapper(iterator);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Array Wrapping iterator
|
|
|
|
* @param a the array that should be wrapped
|
|
|
|
* @return a Iterator that is wrapping a array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a) {
|
2020-11-16 02:55:33 +01:00
|
|
|
return wrap(a, 0, a.length);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Returns a Array Wrapping iterator
|
|
|
|
* @param a the array that should be wrapped.
|
|
|
|
* @param start the index to be started from.
|
|
|
|
* @param end the index that should be ended.
|
|
|
|
* @return a Iterator that is wrapping a array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES ArrayIterator KEY_GENERIC_TYPE wrap(KEY_TYPE[] a, int start, int end) {
|
2020-11-16 02:55:33 +01:00
|
|
|
return new ArrayIteratorBRACES(a, start, end);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i) {
|
2020-11-28 15:05:28 +01:00
|
|
|
return unwrap(a, i, 0, a.length);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @param offset the array offset where the start should be
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset) {
|
2020-12-06 09:32:22 +01:00
|
|
|
return unwrap(a, i, offset, a.length - offset);
|
2020-11-28 15:05:28 +01:00
|
|
|
}
|
2020-12-06 09:32:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @param offset the array offset where the start should be
|
|
|
|
* @param max the maximum values that should be extracted from the source
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, Iterator<? extends CLASS_TYPE> i, int offset, int max) {
|
2020-11-28 15:05:28 +01:00
|
|
|
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
2021-01-08 21:12:20 +01:00
|
|
|
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
2020-11-28 15:05:28 +01:00
|
|
|
int index = 0;
|
|
|
|
for(;index<max && i.hasNext();index++) a[index+offset] = OBJ_TO_KEY(i.next());
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Primitive iterator variant of the {@link #unwrap(KEY_TYPE[], Iterator)} function
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
2020-11-16 02:55:33 +01:00
|
|
|
return unwrap(a, i, 0, a.length);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Primitive iterator variant of the {@link #unwrap(KEY_TYPE[], Iterator, int)} function
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @param offset the array offset where the start should be
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
2020-12-06 09:32:22 +01:00
|
|
|
return unwrap(a, i, offset, a.length - offset);
|
2020-11-16 02:55:33 +01:00
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Primitive iterator variant of the {@link #unwrap(KEY_TYPE[], Iterator, int, int)} function
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @param offset the array offset where the start should be
|
|
|
|
* @param max the maximum values that should be extracted from the source
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(KEY_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
2020-11-16 02:55:33 +01:00
|
|
|
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
2021-01-08 21:12:20 +01:00
|
|
|
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
2020-11-16 02:55:33 +01:00
|
|
|
int index = 0;
|
|
|
|
for(;index<max && i.hasNext();index++) a[index+offset] = i.NEXT();
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !TYPE_OBJECT
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Function to convert a Primitive Iterator to a Object array.
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i) {
|
2020-11-16 02:55:33 +01:00
|
|
|
return unwrap(a, i, 0, a.length);
|
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Function to convert a Primitive Iterator to a Object array.
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @param offset the array offset where the start should be
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset) {
|
2020-12-06 09:32:22 +01:00
|
|
|
return unwrap(a, i, offset, a.length - offset);
|
2020-11-16 02:55:33 +01:00
|
|
|
}
|
|
|
|
|
2020-12-06 09:32:22 +01:00
|
|
|
/**
|
|
|
|
* A Function to convert a Primitive Iterator to a Object array.
|
|
|
|
* Iterates over a iterator and inserts the values into the array and returns the amount that was inserted
|
|
|
|
* @param a where the elements should be inserted
|
|
|
|
* @param i the source iterator
|
|
|
|
* @param offset the array offset where the start should be
|
|
|
|
* @param max the maximum values that should be extracted from the source
|
|
|
|
* @return the amount of elements that were inserted into the array.
|
|
|
|
* @throws IllegalStateException if max is smaller the 0 or if the maximum index is larger then the array
|
|
|
|
*/
|
2021-01-21 21:35:23 +01:00
|
|
|
public static GENERIC_KEY_BRACES int unwrap(CLASS_TYPE[] a, ITERATOR KEY_GENERIC_TYPE i, int offset, int max) {
|
2020-11-16 02:55:33 +01:00
|
|
|
if(max < 0) throw new IllegalStateException("The max size is smaller then 0");
|
2021-01-08 21:12:20 +01:00
|
|
|
if(offset + max > a.length) throw new IllegalStateException("largest array index exceeds array size");
|
2020-11-16 02:55:33 +01:00
|
|
|
int index = 0;
|
|
|
|
for(;index<max && i.hasNext();index++) a[index+offset] = KEY_TO_OBJ(i.NEXT());
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2020-12-13 20:14:22 +01:00
|
|
|
private static class IteratorWrapper implements ITERATOR
|
|
|
|
{
|
|
|
|
Iterator<CLASS_TYPE> iter;
|
|
|
|
|
|
|
|
public IteratorWrapper(Iterator<CLASS_TYPE> iter) {
|
|
|
|
this.iter = iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return iter.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
return OBJ_TO_KEY(iter.next());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Deprecated
|
|
|
|
public CLASS_TYPE next() {
|
|
|
|
return iter.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-01 02:43:13 +01:00
|
|
|
#endif
|
|
|
|
private static class UnmodifiableListIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE
|
|
|
|
{
|
|
|
|
LIST_ITERATOR KEY_GENERIC_TYPE iter;
|
|
|
|
|
|
|
|
UnmodifiableListIterator(LIST_ITERATOR KEY_GENERIC_TYPE iter) {
|
|
|
|
this.iter = iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return iter.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPrevious() {
|
|
|
|
return iter.hasPrevious();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int nextIndex() {
|
|
|
|
return iter.nextIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int previousIndex() {
|
|
|
|
return iter.previousIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() { throw new UnsupportedOperationException(); }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE PREVIOUS() {
|
|
|
|
return iter.PREVIOUS();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
return iter.NEXT();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
2020-12-20 05:45:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static class UnmodifiableBiIterator KEY_GENERIC_TYPE implements BI_ITERATOR KEY_GENERIC_TYPE
|
|
|
|
{
|
|
|
|
BI_ITERATOR KEY_GENERIC_TYPE iter;
|
|
|
|
|
|
|
|
UnmodifiableBiIterator(BI_ITERATOR KEY_GENERIC_TYPE iter) {
|
|
|
|
this.iter = iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
return iter.NEXT();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return iter.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPrevious() {
|
|
|
|
return iter.hasPrevious();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE PREVIOUS() {
|
|
|
|
return iter.PREVIOUS();
|
|
|
|
}
|
|
|
|
}
|
2020-12-01 02:43:13 +01:00
|
|
|
|
|
|
|
private static class UnmodifiableIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
|
|
|
{
|
|
|
|
ITERATOR KEY_GENERIC_TYPE iterator;
|
|
|
|
|
|
|
|
UnmodifiableIterator(ITERATOR KEY_GENERIC_TYPE iterator) {
|
|
|
|
this.iterator = iterator;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return iterator.hasNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
return iterator.NEXT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class EmptyIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
2021-01-21 21:35:23 +01:00
|
|
|
return EMPTY_KEY_VALUE;
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPrevious() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE PREVIOUS() {
|
2021-01-21 21:35:23 +01:00
|
|
|
return EMPTY_KEY_VALUE;
|
2020-12-01 02:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int nextIndex() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int previousIndex() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remove() { throw new UnsupportedOperationException(); }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void set(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void add(KEY_TYPE e) { throw new UnsupportedOperationException(); }
|
|
|
|
}
|
|
|
|
|
2020-11-16 02:55:33 +01:00
|
|
|
private static class ArrayIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
|
|
|
{
|
|
|
|
KEY_TYPE[] a;
|
|
|
|
int from;
|
|
|
|
int to;
|
|
|
|
|
|
|
|
ArrayIterator(KEY_TYPE[] a, int from, int to) {
|
|
|
|
this.a = a;
|
|
|
|
this.from = from;
|
|
|
|
this.to = to;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasNext() {
|
|
|
|
return from < to;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public KEY_TYPE NEXT() {
|
|
|
|
return a[from++];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int skip(int amount) {
|
|
|
|
if(amount < 0) throw new IllegalStateException("Negative Numbers are not allowed");
|
|
|
|
int left = Math.min(amount, to - from);
|
|
|
|
from += left;
|
|
|
|
return amount - left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|