New Stuff
-Fixed: Crash with FIFOQueues peek function when loops were applied. -Fixed: FIFOQueues clean function was doing unessesary extra work. -Added: Stream Overrides functions now support sorted. -Updated: Changelog. -Added: A couple more badges because why not.
This commit is contained in:
+13
-1
@@ -7,12 +7,13 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
|
||||
import speiger.src.collections.PACKAGE.functions.CONSUMER;
|
||||
import speiger.src.collections.PACKAGE.functions.COMPARATOR;
|
||||
#else
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.Comparator;
|
||||
|
||||
#endif
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
@@ -172,6 +173,17 @@ public class ASYNC_BUILDER KEY_GENERIC_TYPE
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the elements inside of the Iterable.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it, and this will affect the pausing feature.
|
||||
* @param sorter that sorts the elements.
|
||||
* @return self with a sorter applied
|
||||
*/
|
||||
public ASYNC_BUILDER KEY_GENERIC_TYPE sorted(COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
iterable = ITERABLES.sorted(iterable, sorter);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to preview elements before they are processed
|
||||
* @param action the action that should be applied
|
||||
|
||||
@@ -3,6 +3,8 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
import java.util.Objects;
|
||||
#if TYPE_BOOLEAN
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
#else if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
#endif
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Consumer;
|
||||
@@ -12,8 +14,11 @@ import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.objects.collections.ObjectIterable;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
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
|
||||
@@ -164,6 +169,30 @@ public class ITERABLES
|
||||
return new LimitedIterableBRACES(wrap(iterable), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterable.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterable that should be sorted
|
||||
* @param sorter that sorts the iterable. Can be null.
|
||||
* @Type(T)
|
||||
* @return a sorted iterable.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE sorted(ITERABLE KEY_GENERIC_TYPE iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIterableBRACES(iterable, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterable from a Java Iterable
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterable that should be sorted
|
||||
* @param sorter that sorts the iterable. Can be null.
|
||||
* @Type(T)
|
||||
* @return a sorted iterable.
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE sorted(Iterable<? extends CLASS_TYPE> iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIterableBRACES(wrap(iterable), sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterable.
|
||||
* @param iterable that should be peeked at
|
||||
@@ -359,6 +388,42 @@ public class ITERABLES
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class SortedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
|
||||
public SortedIterable(ITERABLE KEY_GENERIC_TYPE iterable, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
this.iterable = iterable;
|
||||
this.sorter = sorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.sorted(iterable.iterator(), sorter);
|
||||
}
|
||||
|
||||
#if !TYPE_OBJECT
|
||||
@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);
|
||||
}
|
||||
#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);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static class DistinctIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERABLE KEY_GENERIC_TYPE iterable;
|
||||
|
||||
@@ -3,6 +3,7 @@ package speiger.src.collections.PACKAGE.utils;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
#if TYPE_OBJECT
|
||||
import java.util.Comparator;
|
||||
import java.util.function.CONSUMER;
|
||||
#endif
|
||||
|
||||
@@ -11,6 +12,7 @@ import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
import speiger.src.collections.objects.collections.ObjectIterator;
|
||||
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||
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.PACKAGE.functions.function.PREDICATE;
|
||||
@@ -235,6 +237,30 @@ public class ITERATORS
|
||||
return new LimitedIteratorBRACES(wrap(iterator), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterator beforehand.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterator that should be sorted.
|
||||
* @param sorter the sorter of the iterator. Can be null.
|
||||
* @Type(T)
|
||||
* @return a new sorted iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE sorted(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIteratorBRACES(iterator, sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that sorts the Iterator beforehand from a Java Iterator.
|
||||
* This operation is heavily hurting performance because it rebuilds the entire iterator and then sorts it.
|
||||
* @param iterator that should be sorted.
|
||||
* @param sorter the sorter of the iterator. Can be null.
|
||||
* @Type(T)
|
||||
* @return a new sorted iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE sorted(Iterator<? extends CLASS_TYPE> iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
return new SortedIteratorBRACES(wrap(iterator), sorter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that allows to preview the result of a Iterator.
|
||||
* @param iterator that should be peeked at
|
||||
@@ -871,6 +897,35 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
private static class SortedIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
COMPARATOR KEY_GENERIC_TYPE sorter;
|
||||
LIST KEY_GENERIC_TYPE sortedElements = null;
|
||||
int index = 0;
|
||||
|
||||
public SortedIterator(ITERATOR KEY_GENERIC_TYPE iterator, COMPARATOR KEY_GENERIC_TYPE sorter) {
|
||||
this.iterator = iterator;
|
||||
this.sorter = sorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if(sortedElements == null) {
|
||||
boolean hasNext = iterator.hasNext();
|
||||
sortedElements = hasNext ? pour(iterator) : LISTS.empty();
|
||||
if(hasNext) sortedElements.unstableSort(sorter);
|
||||
}
|
||||
return index < sortedElements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public KEY_TYPE NEXT() {
|
||||
if(!hasNext()) throw new IllegalStateException("End of Iterator");
|
||||
return sortedElements.GET_KEY(index++);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DistinctIterator KEY_GENERIC_TYPE implements ITERATOR KEY_GENERIC_TYPE
|
||||
{
|
||||
ITERATOR KEY_GENERIC_TYPE iterator;
|
||||
|
||||
Reference in New Issue
Block a user