package speiger.src.collections.PACKAGE.collections; #if !TYPE_OBJECT import java.util.Objects; import java.util.function.Consumer; import speiger.src.collections.PACKAGE.functions.CONSUMER; #else import java.util.function.Function; import speiger.src.collections.PACKAGE.utils.ITERATORS; #endif import speiger.src.collections.PACKAGE.collections.SPLIT_ITERATOR; import speiger.src.collections.PACKAGE.utils.SPLIT_ITERATORS; /** * A Type-Specific {@link Iterable} that reduces (un)boxing * @Type(T) */ public interface ITERABLE KEY_GENERIC_TYPE extends Iterable { /** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */ @Override ITERATOR KEY_GENERIC_TYPE iterator(); #if !TYPE_OBJECT /** * A Type Specific foreach function that reduces (un)boxing * * @implSpec *

The default implementation behaves as if: *

{@code
     *     iterator().forEachRemaining(action);
     * }
* * @param action The action to be performed for each element * @throws NullPointerException if the specified action is null * @see Iterable#forEach(Consumer) */ default void forEach(CONSUMER action) { Objects.requireNonNull(action); iterator().forEachRemaining(action); } /** {@inheritDoc} *

This default implementation delegates to the corresponding type-specific function. * @deprecated Please use the corresponding type-specific function instead. */ @Deprecated @Override default void forEach(Consumer action) { Objects.requireNonNull(action); iterator().forEachRemaining(action); } #endif /** * A Type Specific Type Splititerator to reduce boxing/unboxing * @return type specific splititerator */ @Override default SPLIT_ITERATOR KEY_GENERIC_TYPE spliterator() { return SPLIT_ITERATORS.createUnknownSplititerator(iterator(), 0); } #if TYPE_OBJECT /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. * @param map the mapping function * @Type(E) * @return a new Iterable that returns the desired result */ public default ObjectIterable map(Function map) { return ObjectIterators.map(this, map); } /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. * @param map the flatMapping function * @Type(E) * @Type(V) * @return a new Iterable that returns the desired result */ public default > ObjectIterable flatMap(Function map) { return ObjectIterators.flatMap(this, map); } /** * A Helper function to reduce the usage of Streams and allows to convert a Iterable to something else. * @param map the flatMapping function * @Type(E) * @return a new Iterable that returns the desired result */ public default ObjectIterable arrayflatMap(Function map) { return ObjectIterators.arrayFlatMap(this, map); } #endif }