Skip to content

Commit

Permalink
Added java type support for Stream replacer functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Speiger committed Sep 28, 2021
1 parent 0e06192 commit 3c5769e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 3c5769e

Please sign in to comment.