Implemented Lists can now be Disabled
Each List implementation can be now turned off. Or all Lists can be turned off. ListIterator can't be turned of since it is a IndexBasedIterator and not a List and a few implementation use them.
This commit is contained in:
@@ -9,10 +9,11 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
import java.util.Comparator;
|
||||
|
||||
import speiger.src.collections.ints.functions.function.Int2ObjectFunction;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.utils.ITERATORS;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
@@ -132,10 +133,39 @@ public class ARRAYS
|
||||
* @return array with all requested elements of the iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max) {
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper();
|
||||
ITERATORS.pour(iter, list, max);
|
||||
return list.TO_ARRAY(NEW_KEY_ARRAY(list.size()));
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that pours all elements of a iterator into a Array
|
||||
* @param iter the elements that should be gathered.
|
||||
* @ArrayType(T)
|
||||
* @param action that is creating the Array to be poured into
|
||||
* @return array with all elements of the iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||
return pour(iter, Integer.MAX_VALUE, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that pours all elements of a iterator into a Array
|
||||
* @param iter the elements that should be gathered.
|
||||
* @param max how many elements should be added
|
||||
* @param action that is creating the Array to be poured into
|
||||
* @ArrayType(T)
|
||||
* @return array with all requested elements of the iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES KEY_TYPE[] pour(ITERATOR KEY_GENERIC_TYPE iter, int max, Int2ObjectFunction<KEY_TYPE[]> action) {
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE list = COLLECTIONS.wrapper();
|
||||
ITERATORS.pour(iter, list, max);
|
||||
return list.TO_ARRAY(action.apply(list.size()));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Method to validate if the current value is the lowest value in the heap
|
||||
* @param data the current heap.
|
||||
|
||||
+13
-2
@@ -27,9 +27,12 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
#else if LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN
|
||||
import speiger.src.collections.PACKAGE.sets.SET;
|
||||
import speiger.src.collections.PACKAGE.sets.LINKED_HASH_SET;
|
||||
@@ -119,6 +122,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ASYNC_BUILDERBRACES(ITERABLES.wrap(iterable));
|
||||
}
|
||||
|
||||
#if ARRAY_LIST_FEATURE
|
||||
/**
|
||||
* Helper function that automatically wraps a array into a AsyncBuilder since it forces this collections Iterable.
|
||||
* @param values that should be wrapped
|
||||
@@ -129,6 +133,7 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return new ASYNC_BUILDERBRACES(ARRAY_LIST.wrap(values));
|
||||
}
|
||||
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
/**
|
||||
* Maps the elements to something else
|
||||
@@ -268,14 +273,20 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
|
||||
#endif
|
||||
#if OBJECT_ASYNC_MODULE
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* Pours all elements into a List that can be later
|
||||
* @return a new Builder with the pour function applied
|
||||
*/
|
||||
public ObjectAsyncBuilder<LIST KEY_GENERIC_TYPE> pourAsList() {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
return pour(new ARRAY_LISTBRACES());
|
||||
#else
|
||||
return pour(new LINKED_LISTBRACES());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#if !TYPE_BOOLEAN
|
||||
/**
|
||||
* Pours all elements into a Set that can be later
|
||||
|
||||
+203
@@ -1,7 +1,10 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.BiFunction;
|
||||
#endif
|
||||
import java.util.function.Predicate;
|
||||
@@ -13,6 +16,9 @@ import java.util.function.Consumer;
|
||||
import speiger.src.collections.PACKAGE.collections.ABSTRACT_COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.objects.utils.ObjectArrays;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
@@ -21,6 +27,9 @@ import speiger.src.collections.PACKAGE.utils.ARRAYS;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
import speiger.src.collections.PACKAGE.functions.function.UNARY_OPERATOR;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
import speiger.src.collections.utils.ITrimmable;
|
||||
import speiger.src.collections.utils.SanityChecks;
|
||||
|
||||
/**
|
||||
* A Helper class for Collections
|
||||
*/
|
||||
@@ -75,6 +84,200 @@ public class COLLECTIONS
|
||||
return c instanceof SynchronizedCollection ? c : new SynchronizedCollectionBRACES(c, mutex);
|
||||
}
|
||||
|
||||
protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper() {
|
||||
return new CollectionWrapperBRACES();
|
||||
}
|
||||
|
||||
protected static GENERIC_KEY_BRACES CollectionWrapper KEY_GENERIC_TYPE wrapper(int size) {
|
||||
return new CollectionWrapperBRACES(size);
|
||||
}
|
||||
|
||||
protected static class CollectionWrapper KEY_GENERIC_TYPE extends ABSTRACT_COLLECTION KEY_GENERIC_TYPE implements ITrimmable {
|
||||
KEY_TYPE[] elements;
|
||||
int size = 0;
|
||||
|
||||
public CollectionWrapper() {
|
||||
this(10);
|
||||
}
|
||||
|
||||
public CollectionWrapper(int size) {
|
||||
if(size < 0) throw new IllegalStateException("Size has to be 0 or greater");
|
||||
elements = NEW_KEY_ARRAY(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(KEY_TYPE o) {
|
||||
if(size >= elements.length) elements = Arrays.copyOf(elements, (int)Math.min((long)elements.length + (elements.length >> 1), SanityChecks.MAX_ARRAY_SIZE));
|
||||
elements[size++] = o;
|
||||
return true;
|
||||
}
|
||||
|
||||
public KEY_TYPE GET_KEY(int index) {
|
||||
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
@Override
|
||||
public boolean remove(Object e) {
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS(elements[i], e)) {
|
||||
removeIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
@Override
|
||||
public boolean REMOVE_KEY(KEY_TYPE e) {
|
||||
for(int i = 0;i<size;i++) {
|
||||
if(KEY_EQUALS(elements[i], e)) {
|
||||
removeIndex(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
private void removeIndex(int index) {
|
||||
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size);
|
||||
size--;
|
||||
if(index != size) System.arraycopy(elements, index+1, elements, index, size - index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return new ITERATOR KEY_GENERIC_TYPE() {
|
||||
int index = 0;
|
||||
int lastReturned = -1;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return index < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
int i = index++;
|
||||
return elements[(lastReturned = i)];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(lastReturned == -1) throw new IllegalStateException();
|
||||
removeIndex(lastReturned);
|
||||
index = lastReturned;
|
||||
lastReturned = -1;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
#if TYPE_OBJECT
|
||||
for(int i = 0;i<size;elements[i] = null,i++);
|
||||
#endif
|
||||
size = 0;
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
public void sort(Comparator<? super CLASS_TYPE> c) {
|
||||
if(c != null) ARRAYS.stableSort(elements, size, c);
|
||||
else ARRAYS.stableSort(elements, size);
|
||||
}
|
||||
|
||||
public void unstableSort(Comparator<? super CLASS_TYPE> c) {
|
||||
if(c != null) ARRAYS.unstableSort(elements, size, c);
|
||||
else ARRAYS.unstableSort(elements, size);
|
||||
}
|
||||
|
||||
#else
|
||||
public void sort(COMPARATOR c) {
|
||||
if(c != null) ARRAYS.stableSort(elements, size, c);
|
||||
else ARRAYS.stableSort(elements, size);
|
||||
}
|
||||
|
||||
public void unstableSort(COMPARATOR c) {
|
||||
if(c != null) ARRAYS.unstableSort(elements, size, c);
|
||||
else ARRAYS.unstableSort(elements, size);
|
||||
}
|
||||
|
||||
#endif
|
||||
@Override
|
||||
public void forEach(CONSUMER KEY_SUPER_GENERIC_TYPE action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(elements[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E> void forEach(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) {
|
||||
Objects.requireNonNull(action);
|
||||
for(int i = 0;i<size;i++)
|
||||
action.accept(input, elements[i]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trim(int size) {
|
||||
if(size > size() || size() == elements.length) return false;
|
||||
int value = Math.max(size, size());
|
||||
elements = value == 0 ? EMPTY_KEY_ARRAY : Arrays.copyOf(elements, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAndTrim(int size) {
|
||||
if(elements.length <= size) {
|
||||
clear();
|
||||
return;
|
||||
}
|
||||
elements = size == 0 ? EMPTY_KEY_ARRAY : NEW_KEY_ARRAY(size);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public Object[] toArray() {
|
||||
Object[] obj = new Object[size];
|
||||
for(int i = 0;i<size;i++)
|
||||
obj[i] = KEY_TO_OBJ(elements[i]);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Primitive
|
||||
public <E> E[] toArray(E[] a) {
|
||||
if(a == null) a = (E[])new Object[size];
|
||||
else if(a.length < size) a = (E[])ObjectArrays.newArray(a.getClass().getComponentType(), size);
|
||||
#if TYPE_OBJECT
|
||||
System.arraycopy(elements, 0, a, 0, size);
|
||||
#else
|
||||
for(int i = 0;i<size;i++)
|
||||
a[i] = (E)KEY_TO_OBJ(elements[i]);
|
||||
#endif
|
||||
if (a.length > size) a[size] = null;
|
||||
return a;
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public KEY_TYPE[] TO_ARRAY(KEY_TYPE[] a) {
|
||||
if(a.length < size) a = new KEY_TYPE[size];
|
||||
System.arraycopy(elements, 0, a, 0, size);
|
||||
if (a.length > size) a[size] = EMPTY_KEY_VALUE;
|
||||
return a;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronized Collection Wrapper for the synchronizedCollection function
|
||||
* @Type(T)
|
||||
|
||||
@@ -7,7 +7,9 @@ import speiger.src.collections.utils.IArray;
|
||||
|
||||
/**
|
||||
* Type-Specific Helper class to get the underlying array of array implementations.
|
||||
#if ARRAY_LIST_FEATURE
|
||||
* @see speiger.src.collections.PACKAGE.lists.ARRAY_LIST
|
||||
#endif
|
||||
* @Type(T)
|
||||
*/
|
||||
public interface IARRAY KEY_GENERIC_TYPE extends IArray
|
||||
|
||||
+15
-16
@@ -10,6 +10,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if !TYPE_OBJECT
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
@@ -17,8 +18,6 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#if !TYPE_BOOLEAN
|
||||
@@ -380,19 +379,19 @@ public class ITERABLES
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(action.andThen(list::add));
|
||||
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||
iterable.forEach(action.andThen(repeater::add));
|
||||
for(int i = 0;i<repeats;i++)
|
||||
list.forEach(action);
|
||||
repeater.forEach(action);
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(T -> {action.accept(T); list.add(T);});
|
||||
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||
iterable.forEach(T -> {action.accept(T); repeater.add(T);});
|
||||
for(int i = 0;i<repeats;i++)
|
||||
list.forEach(action);
|
||||
repeater.forEach(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -496,19 +495,19 @@ public class ITERABLES
|
||||
@Override
|
||||
public void forEach(CONSUMER action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(list::add);
|
||||
list.unstableSort(sorter);
|
||||
list.forEach(action);
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper = COLLECTIONS.wrapper();
|
||||
iterable.forEach(wrapper::add);
|
||||
wrapper.unstableSort(sorter);
|
||||
wrapper.forEach(action);
|
||||
}
|
||||
#else
|
||||
@Override
|
||||
public void forEach(Consumer<? super CLASS_TYPE> action) {
|
||||
Objects.requireNonNull(action);
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
iterable.forEach(list::add);
|
||||
list.unstableSort(sorter);
|
||||
list.forEach(action);
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE wrapper = COLLECTIONS.wrapper();
|
||||
iterable.forEach(wrapper::add);
|
||||
wrapper.unstableSort(sorter);
|
||||
wrapper.forEach(action);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+33
-34
@@ -16,8 +16,13 @@ import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#if LIST_MODULE
|
||||
#if ARRAY_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.ARRAY_LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
#else if LINKED_LIST_FEATURE
|
||||
import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
||||
#endif
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
@@ -468,6 +473,8 @@ public class ITERATORS
|
||||
}
|
||||
|
||||
#endif
|
||||
#if LIST_MODULE
|
||||
#if ARRAY_LIST_FEATURE || LINKED_LIST_FEATURE
|
||||
/**
|
||||
* A Helper function to pours all elements of a Iterator into a List
|
||||
* @param iter the elements that should be poured into list.
|
||||
@@ -486,12 +493,20 @@ public class ITERATORS
|
||||
* @return A list of all requested elements of the Iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES LIST KEY_GENERIC_TYPE pour(ITERATOR KEY_GENERIC_TYPE iter, int max) {
|
||||
#if ARRAY_LIST_FEATURE
|
||||
ARRAY_LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
#else
|
||||
LINKED_LIST KEY_GENERIC_TYPE list = new LINKED_LISTBRACES();
|
||||
#endif
|
||||
pour(iter, list, max);
|
||||
#if ARRAY_LIST_FEATURE
|
||||
list.trim();
|
||||
#endif
|
||||
return list;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* A Helper function to pours all elements of a Iterator into a Collection
|
||||
* @param iter the elements that should be poured into list.
|
||||
@@ -624,7 +639,7 @@ public class ITERATORS
|
||||
@Override
|
||||
public void remove() { it.remove(); }
|
||||
}
|
||||
|
||||
|
||||
private static class ReverseListIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE {
|
||||
LIST_ITERATOR KEY_GENERIC_TYPE it;
|
||||
|
||||
@@ -747,45 +762,25 @@ public class ITERATORS
|
||||
return iterator.NEXT();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class EmptyIterator KEY_GENERIC_TYPE implements LIST_ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNext() { return false; }
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public KEY_TYPE NEXT() { throw new NoSuchElementException(); }
|
||||
@Override
|
||||
public boolean hasPrevious() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasPrevious() { return false; }
|
||||
@Override
|
||||
public KEY_TYPE PREVIOUS() {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
public KEY_TYPE PREVIOUS() { throw new NoSuchElementException(); }
|
||||
@Override
|
||||
public int nextIndex() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int nextIndex() { return 0; }
|
||||
@Override
|
||||
public int previousIndex() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int previousIndex() { return -1; }
|
||||
@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(); }
|
||||
}
|
||||
@@ -925,7 +920,7 @@ public class ITERATORS
|
||||
final int repeats;
|
||||
int index = 0;
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
LIST KEY_GENERIC_TYPE list = new ARRAY_LISTBRACES();
|
||||
COLLECTION KEY_GENERIC_TYPE repeater = COLLECTIONS.wrapper();
|
||||
|
||||
public RepeatingIterator(ITERATOR KEY_GENERIC_TYPE iter, int repeat) {
|
||||
this.iter = iter;
|
||||
@@ -937,7 +932,7 @@ public class ITERATORS
|
||||
if(iter.hasNext()) return true;
|
||||
if(index < repeats) {
|
||||
index++;
|
||||
iter = list.iterator();
|
||||
iter = repeater.iterator();
|
||||
return iter.hasNext();
|
||||
}
|
||||
return false;
|
||||
@@ -947,7 +942,7 @@ public class ITERATORS
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new NoSuchElementException();
|
||||
KEY_TYPE value = iter.NEXT();
|
||||
if(index == 0) list.add(value);
|
||||
if(index == 0) repeater.add(value);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -956,7 +951,7 @@ public class ITERATORS
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
LIST KEY_GENERIC_TYPE sortedElements = null;
|
||||
COLLECTIONS.CollectionWrapper KEY_GENERIC_TYPE sortedElements = null;
|
||||
int index = 0;
|
||||
|
||||
public SortedIterator(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
@@ -968,7 +963,11 @@ public class ITERATORS
|
||||
public boolean hasNext() {
|
||||
if(sortedElements == null) {
|
||||
boolean hasNext = iterator.hasNext();
|
||||
sortedElements = hasNext ? pour(iterator) : LISTS.empty();
|
||||
if(hasNext) {
|
||||
sortedElements = COLLECTIONS.wrapper();
|
||||
pour(iterator, sortedElements);
|
||||
}
|
||||
else sortedElements = COLLECTIONS.wrapper();
|
||||
if(hasNext) sortedElements.unstableSort(sorter);
|
||||
}
|
||||
return index < sortedElements.size();
|
||||
|
||||
Reference in New Issue
Block a user