Started Next larger patch.
- Changed: Iterable specific helper functions were moved out of Iterators and moved into Iterables - Added: New Stream replacing functions: findFirst, matchesAny/All/None
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
package speiger.src.collections.PACKAGE.utils;
|
||||
|
||||
#if TYPE_OBJECT
|
||||
import java.util.function.Function;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
import speiger.src.collections.PACKAGE.collections.ITERATOR;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Helper class for Iterables
|
||||
*/
|
||||
public class ITERABLES
|
||||
{
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that maps a 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)
|
||||
* @Type(E)
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static <T, E> ITERABLE<T> map(ITERABLE<E> iterable, Function<E, T> mapper) {
|
||||
return new MappedIterableBRACES(iterable, mapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a 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)
|
||||
* @Type(V)
|
||||
* @Type(E)
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static <T, E, V extends Iterable<T>> ITERABLE<T> flatMap(ITERABLE<E> iterable, Function<E, V> mapper) {
|
||||
return new FlatMappedIterableBRACES(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a 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)
|
||||
* @Type(E)
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static <T, E> ITERABLE<T> arrayFlatMap(ITERABLE<E> iterable, Function<E, T[]> mapper) {
|
||||
return new FlatMappedArrayIterableBRACES(iterable, mapper);
|
||||
}
|
||||
|
||||
private static class MappedIterable<E, T> implements ITERABLE<T>
|
||||
{
|
||||
ITERABLE<E> iterable;
|
||||
Function<E, T> mapper;
|
||||
|
||||
MappedIterable(ITERABLE<E> iterable, Function<E, T> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public ITERATOR<T> iterator() {
|
||||
return ITERATORS.map(iterable.iterator(), mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedIterable<E, T, V extends Iterable<T>> implements ITERABLE<T>
|
||||
{
|
||||
ITERABLE<E> iterable;
|
||||
Function<E, V> mapper;
|
||||
|
||||
FlatMappedIterable(ITERABLE<E> iterable, Function<E, V> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR<T> iterator() {
|
||||
return ITERATORS.flatMap(iterable.iterator(), mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedArrayIterable<E, T> implements ITERABLE<T>
|
||||
{
|
||||
ITERABLE<E> iterable;
|
||||
Function<E, T[]> mapper;
|
||||
|
||||
FlatMappedArrayIterable(ITERABLE<E> iterable, Function<E, T[]> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR<T> iterator() {
|
||||
return ITERATORS.arrayFlatMap(iterable.iterator(), mapper);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -12,9 +12,6 @@ import speiger.src.collections.PACKAGE.lists.LIST;
|
||||
import speiger.src.collections.PACKAGE.lists.LIST_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.BI_ITERATOR;
|
||||
import speiger.src.collections.PACKAGE.collections.COLLECTION;
|
||||
#if TYPE_OBJECT
|
||||
import speiger.src.collections.PACKAGE.collections.ITERABLE;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Helper class for Iterators
|
||||
@@ -90,18 +87,6 @@ public class ITERATORS
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
/**
|
||||
* A Helper function that maps a 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)
|
||||
* @Type(E)
|
||||
* @return a iterable that is mapped to a new result
|
||||
*/
|
||||
public static <T, E> ITERABLE<T> map(ITERABLE<E> iterable, Function<E, T> mapper) {
|
||||
return new MappedIterableBRACES(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that maps a Iterator into a new Type.
|
||||
* @param iterator that should be mapped
|
||||
@@ -114,31 +99,6 @@ public class ITERATORS
|
||||
return new MappedIteratorBRACES(iterator, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a 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)
|
||||
* @Type(V)
|
||||
* @Type(E)
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static <T, E, V extends Iterable<T>> ITERABLE<T> flatMap(ITERABLE<E> iterable, Function<E, V> mapper) {
|
||||
return new FlatMappedIterableBRACES(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a 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)
|
||||
* @Type(E)
|
||||
* @return a iterable that is flatMapped to a new result
|
||||
*/
|
||||
public static <T, E> ITERABLE<T> arrayFlatMap(ITERABLE<E> iterable, Function<E, T[]> mapper) {
|
||||
return new FlatMappedArrayIterableBRACES(iterable, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Helper function that flatMaps a Iterator into a new Type.
|
||||
* @param iterator that should be flatMapped
|
||||
@@ -682,21 +642,6 @@ public class ITERATORS
|
||||
}
|
||||
|
||||
#if TYPE_OBJECT
|
||||
private static class MappedIterable<E, T> implements ITERABLE<T>
|
||||
{
|
||||
ITERABLE<E> iterable;
|
||||
Function<E, T> mapper;
|
||||
|
||||
MappedIterable(ITERABLE<E> iterable, Function<E, T> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public ITERATOR<T> iterator() {
|
||||
return new MappedIterator<>(iterable.iterator(), mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MappedIterator<E, T> implements ITERATOR<T>
|
||||
{
|
||||
ITERATOR<E> iterator;
|
||||
@@ -723,38 +668,6 @@ public class ITERATORS
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedIterable<E, T, V extends Iterable<T>> implements ITERABLE<T>
|
||||
{
|
||||
ITERABLE<E> iterable;
|
||||
Function<E, V> mapper;
|
||||
|
||||
FlatMappedIterable(ITERABLE<E> iterable, Function<E, V> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR<T> iterator() {
|
||||
return new FlatMappedIterator<>(iterable.iterator(), mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedArrayIterable<E, T> implements ITERABLE<T>
|
||||
{
|
||||
ITERABLE<E> iterable;
|
||||
Function<E, T[]> mapper;
|
||||
|
||||
FlatMappedArrayIterable(ITERABLE<E> iterable, Function<E, T[]> mapper) {
|
||||
this.iterable = iterable;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITERATOR<T> iterator() {
|
||||
return new FlatMappedArrayIterator<>(iterable.iterator(), mapper);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FlatMappedIterator<E, T, V extends Iterable<T>> implements ITERATOR<T>
|
||||
{
|
||||
ITERATOR<E> iterator;
|
||||
|
||||
Reference in New Issue
Block a user