forked from Speiger/Primitive-Collections
Added Infinite Iterators
This commit is contained in:
parent
6af0656216
commit
a89c812c06
|
@ -6,6 +6,7 @@
|
|||
- Added: ToArray/pushTop functions to Stack.class.
|
||||
- Added: ComputeNonDefault functions which will contain the current behavior of the Compute function, while the Compute will be changed to be more java compliant!
|
||||
- Added: List.reversed, which returns a SubList that has all elements in reversed order and also inserts reversed.
|
||||
- Added: Iterators.infinite as an option that will create a Infinite Iterator based on the inputted one.
|
||||
- Fixed: SetValue wasn't working on forEach implementations.
|
||||
- Fixed: Compute functions now perform with primitives more java compliant. Meaning that getDefaultReturnValue function no longer is seen as null.
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import java.util.Iterator;
|
|||
import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.CONSUMER;
|
||||
#endif
|
||||
import java.util.function.Consumer;
|
||||
#if JDK_FUNCTION
|
||||
import java.util.function.PREDICATE;
|
||||
#endif
|
||||
|
@ -18,6 +18,7 @@ import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
|||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.functions.function.TO_OBJECT_FUNCTION;
|
||||
import speiger.src.collections.objects.functions.consumer.BI_FROM_OBJECT_CONSUMER;
|
||||
#if !JDK_FUNCTION
|
||||
import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
||||
#endif
|
||||
|
@ -33,6 +34,7 @@ import speiger.src.collections.PACKAGE.lists.LINKED_LIST;
|
|||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
import speiger.src.collections.PACKAGE.utils.COLLECTIONS.CollectionWrapper;
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
|
@ -245,6 +247,26 @@ public class ITERATORS
|
|||
return new RepeatingIteratorBRACES(wrap(iterator), repeats);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @Type(T)
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(ITERATOR KEY_GENERIC_TYPE iterator) {
|
||||
return new InfiniteIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that creates a infinitely looping iterator from a Java Iterator
|
||||
* @param iterator that should be looping infinitely
|
||||
* @Type(T)
|
||||
* @return a infinitely looping iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE infinite(Iterator<? extends CLASS_TYPE> iterator) {
|
||||
return new InfiniteIteratorBRACES(wrap(iterator));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that hard limits the Iterator to a specific size
|
||||
* @param iterator that should be limited
|
||||
|
@ -918,6 +940,42 @@ public class ITERATORS
|
|||
}
|
||||
}
|
||||
|
||||
private static class InfiniteIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iter;
|
||||
CollectionWrapper KEY_GENERIC_TYPE looper = COLLECTIONS.wrapper();
|
||||
int index = 0;
|
||||
|
||||
public InfiniteIterator(ITERATOR KEY_GENERIC_TYPE iter) {
|
||||
this.iter = iter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(iter != null) {
|
||||
if(iter.hasNext()) {
|
||||
KEY_TYPE value = iter.NEXT();
|
||||
looper.add(value);
|
||||
return value;
|
||||
}
|
||||
else iter = null;
|
||||
}
|
||||
return looper.GET_KEY((index++) % looper.size());
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@Override
|
||||
public void forEachRemaining(CONSUMER action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
#endif
|
||||
public void forEachRemaining(Consumer<? super CLASS_TYPE> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
public <E> void forEachRemaining(E input, BI_FROM_OBJECT_CONSUMER KSK_GENERIC_TYPE<E> action) { throw new UnsupportedOperationException("This is a instant deadlock, so unsupported"); }
|
||||
}
|
||||
|
||||
private static class RepeatingIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
final int repeats;
|
||||
|
|
Loading…
Reference in New Issue