Package org.cyclos.server.utils
Class CloseableIteratorHelper
- java.lang.Object
-
- org.cyclos.server.utils.CloseableIteratorHelper
-
public class CloseableIteratorHelper extends Object
Contains helper methods to work withCloseableIterators
-
-
Constructor Summary
Constructors Constructor Description CloseableIteratorHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Stream<T>asStream(com.mysema.commons.lang.CloseableIterator<T> iterator)Returns aStreamequivalent to the given iterator.static <T> com.mysema.commons.lang.CloseableIterator<T>chained(com.mysema.commons.lang.CloseableIterator<? extends T>... iterators)Returns aStreamequivalent to the given iteratorstatic <T> com.mysema.commons.lang.CloseableIterator<T>empty()Returns an emptyCloseableIteratorstatic <T> com.mysema.commons.lang.CloseableIterator<T>filtered(com.mysema.commons.lang.CloseableIterator<T> iterator, Predicate<T> filter)Returns aCloseableIteratorthat skips elements that don't match the given filterstatic <T> com.mysema.commons.lang.CloseableIterator<T>lazy(Supplier<com.mysema.commons.lang.CloseableIterator<T>> supplier)Returns aCloseableIteratorthat only initializes on hasNext() and next()static <T> Pair<T,com.mysema.commons.lang.CloseableIterator<T>>peekFirst(com.mysema.commons.lang.CloseableIterator<T> iterator)Peeks the first element of an iterator, returning it together with another iterator similar to the given one (also including the first element)static <T> com.mysema.commons.lang.CloseableIterator<T>singleton(T element)Returns aCloseableIteratorwith a single element.
-
-
-
Method Detail
-
asStream
public static <T> Stream<T> asStream(com.mysema.commons.lang.CloseableIterator<T> iterator)
Returns aStreamequivalent to the given iterator. The returnedStreamdoesn't need to be closed after a terminal operation, because it will be wrapped in aStream.flatMap(java.util.function.Function)call, which by definition closes the stream after a terminal operation.
-
chained
@SafeVarargs public static <T> com.mysema.commons.lang.CloseableIterator<T> chained(com.mysema.commons.lang.CloseableIterator<? extends T>... iterators)
Returns aStreamequivalent to the given iterator
-
empty
public static <T> com.mysema.commons.lang.CloseableIterator<T> empty()
Returns an emptyCloseableIterator
-
filtered
public static <T> com.mysema.commons.lang.CloseableIterator<T> filtered(com.mysema.commons.lang.CloseableIterator<T> iterator, Predicate<T> filter)Returns aCloseableIteratorthat skips elements that don't match the given filter
-
lazy
public static <T> com.mysema.commons.lang.CloseableIterator<T> lazy(Supplier<com.mysema.commons.lang.CloseableIterator<T>> supplier)
Returns aCloseableIteratorthat only initializes on hasNext() and next()
-
peekFirst
public static <T> Pair<T,com.mysema.commons.lang.CloseableIterator<T>> peekFirst(com.mysema.commons.lang.CloseableIterator<T> iterator)
Peeks the first element of an iterator, returning it together with another iterator similar to the given one (also including the first element)
-
singleton
public static <T> com.mysema.commons.lang.CloseableIterator<T> singleton(T element)
Returns aCloseableIteratorwith a single element. Closing is no-op.
-
-