forked from Speiger/Primitive-Collections
Added java type support for Stream replacer functions.
This commit is contained in:
parent
0e061921e9
commit
3c5769e0e2
|
@ -14,6 +14,18 @@ import speiger.src.collections.PACKAGE.functions.function.PREDICATE;
|
|||
*/
|
||||
public class ITERABLES
|
||||
{
|
||||
/**
|
||||
* A Helper function that maps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> map(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||
return new MappedIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be mapped
|
||||
|
@ -26,6 +38,19 @@ public class ITERABLES
|
|||
return new MappedIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterable<E> flatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return new FlatMappedIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
|
@ -39,6 +64,18 @@ public class ITERABLES
|
|||
return new FlatMappedIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterable<E> arrayFlatMap(Iterable<? extends CLASS_TYPE> iterable, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return new FlatMappedArrayIterable<>(wrap(iterable), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterable into a new Type.
|
||||
* @param iterable the iterable that should be flatMapped
|
||||
|
@ -51,6 +88,17 @@ public class ITERABLES
|
|||
return new FlatMappedArrayIterable<>(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements from a Java-Iterable
|
||||
* @param iterable that should be filtered.
|
||||
* @param filter the filter that decides that should be let through
|
||||
* @Type(T)
|
||||
* @return a filtered iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE filter(Iterable<? extends CLASS_TYPE> iterable, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return new FilteredIterableBRACES(wrap(iterable), filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements
|
||||
* @param iterable that should be filtered.
|
||||
|
@ -62,6 +110,28 @@ public class ITERABLES
|
|||
return new FilteredIterableBRACES(iterable, filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Wrapper function that wraps a Java-Iterable into a Type Specific Iterable
|
||||
* @param iterable that should be wrapped
|
||||
* @return a type specific iterable
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERABLE KEY_GENERIC_TYPE wrap(Iterable<? extends CLASS_TYPE> iterable) {
|
||||
return new WrappedIterableBRACES(iterable);
|
||||
}
|
||||
|
||||
private static class WrappedIterable KEY_GENERIC_TYPE implements ITERABLE KEY_GENERIC_TYPE
|
||||
{
|
||||
Iterable<? extends CLASS_TYPE> iterable;
|
||||
|
||||
public WrappedIterable(Iterable<? extends CLASS_TYPE> iterable) {
|
||||
this.iterable = iterable;
|
||||
}
|
||||
|
||||
public ITERATOR KEY_GENERIC_TYPE iterator() {
|
||||
return ITERATORS.wrap(iterable.iterator());
|
||||
}
|
||||
}
|
||||
|
||||
private static class MappedIterable KSS_GENERIC_TYPE<E, T> implements ObjectIterable<T>
|
||||
{
|
||||
ITERABLE KEY_SPECIAL_GENERIC_TYPE<E> iterable;
|
||||
|
|
|
@ -89,6 +89,18 @@ public class ITERATORS
|
|||
return iterator instanceof UnmodifiableListIterator ? iterator : new UnmodifiableListIteratorBRACES(iterator);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterator that is mapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterator<E> map(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E> mapper) {
|
||||
return new MappedIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
|
@ -101,6 +113,19 @@ public class ITERATORS
|
|||
return new MappedIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <V> The return type supplier.
|
||||
* @param <E> The return type.
|
||||
* @return a iterator that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E, V extends Iterable<E>> ObjectIterator<E> flatMap(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<V> mapper) {
|
||||
return new FlatMappedIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
|
@ -114,6 +139,18 @@ public class ITERATORS
|
|||
return new FlatMappedIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Java-Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
* @param mapper the function that decides what the result turns into.
|
||||
* @Type(T)
|
||||
* @param <E> The return type.
|
||||
* @return a iterator that is flatMapped to a new result
|
||||
*/
|
||||
public static GENERIC_KEY_SPECIAL_BRACES<E> ObjectIterator<E> arrayFlatMap(Iterator<? extends CLASS_TYPE> iterator, TO_OBJECT_FUNCTION KKS_GENERIC_TYPE<E[]> mapper) {
|
||||
return new FlatMappedArrayIterator<>(wrap(iterator), mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
|
@ -126,6 +163,17 @@ public class ITERATORS
|
|||
return new FlatMappedArrayIterator<>(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements from a Java-Iterator
|
||||
* @param iterator that should be filtered.
|
||||
* @param filter the filter that decides that should be let through
|
||||
* @Type(T)
|
||||
* @return a filtered iterator
|
||||
*/
|
||||
public static GENERIC_KEY_BRACES ITERATOR KEY_GENERIC_TYPE filter(Iterator<? extends CLASS_TYPE> iterator, PREDICATE KEY_GENERIC_TYPE filter) {
|
||||
return new FilteredIteratorBRACES(wrap(iterator), filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that filters out all desired elements
|
||||
* @param iterator that should be filtered.
|
||||
|
|
Loading…
Reference in New Issue