Package org.openrefine.util
Interface CloseableIterator<T>
-
- Type Parameters:
T
- the type of element being iterated on
- All Superinterfaces:
AutoCloseable
,io.vavr.collection.Foldable<T>
,Iterable<T>
,io.vavr.collection.Iterator<T>
,Iterator<T>
,io.vavr.collection.Traversable<T>
,io.vavr.Value<T>
- All Known Implementing Classes:
CloseableIterator.Wrapper
public interface CloseableIterator<T> extends io.vavr.collection.Iterator<T>, AutoCloseable
An iterator which may be derived from resources that should be closed once the iterator is no longer needed. This is used in the local runner to make it possible to iterate from partitions stored on disk and close the file descriptors as soon as iteration stops.
The Java 8 Stream API is often recommended as a closeable "iterator-like" API but in our case it cannot be used because in some circumstances it buffers the stream, forcing the loading of an entire partition in memory while only the first few rows in it are actually needed.
Like in the Java 8 Stream API, some methods return a new iterator and some others are a terminal action. Users should only close the iterator after using a terminal action, not after using a method that returns a new iterator. The derived iterator itself should be closed when a terminal action is called on it, and that will recursively call theclose()
method of the original iterator. Methods which derive an iterator from multiple iterators will close all the underlying iterators when they are closed themselves. For this reason, one should not derive multiple iterators from the same iterator, as they are using the same underlying resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
CloseableIterator.Wrapper<T>
A wrapper which takes a plain iterator and turns it into a closeable one.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default io.vavr.collection.Iterator<io.vavr.collection.Iterator<T>>
chop(io.vavr.collection.Iterator<Integer> lengths)
Consumes the iterator by splitting it into chunks of the desired length.void
close()
Releases all resources underpinning this iterator.default <R> CloseableIterator<R>
collect(io.vavr.PartialFunction<? super T,? extends R> partialFunction)
default CloseableIterator<T>
concat(CloseableIterator<? extends T> that)
default CloseableIterator<T>
distinct()
default CloseableIterator<T>
distinctBy(Comparator<? super T> comparator)
default <U> CloseableIterator<T>
distinctBy(Function<? super T,? extends U> keyExtractor)
default CloseableIterator<T>
drop(int n)
default CloseableIterator<T>
dropRight(int n)
default CloseableIterator<T>
dropUntil(Predicate<? super T> predicate)
default CloseableIterator<T>
dropWhile(Predicate<? super T> predicate)
static <T> CloseableIterator<T>
empty()
default CloseableIterator<T>
filter(Predicate<? super T> predicate)
default <U> io.vavr.collection.Iterator<U>
flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
Deprecated.This method should not be called as it discards the pointers to the closeable resources.default <U> CloseableIterator<U>
flatMapCloseable(Function<? super T,? extends CloseableIterator<? extends U>> mapper)
static CloseableIterator<Long>
from(long start)
default CloseableIterator<io.vavr.collection.Seq<T>>
grouped(int size)
boolean
hasNext()
Checks if the iterator contains a next element.default CloseableIterator<T>
init()
default CloseableIterator<T>
intersperse(T element)
default CloseableIterator<T>
iterator()
default <U> CloseableIterator<U>
map(Function<? super T,? extends U> mapper)
T
next()
Returns the next element in the stream if there is one available.static <T> CloseableIterator<T>
of(T... elements)
static <T> CloseableIterator<T>
ofAll(Iterable<? extends T> ts)
default io.vavr.collection.Iterator<T>
orElse(Iterable<? extends T> other)
Deprecated.This method should not be called as it discards the pointers to the closeable resources.default CloseableIterator<T>
orElse(Supplier<? extends Iterable<? extends T>> supplier)
Deprecated.This method should not be called as it discards the pointers to the closeable resources.default CloseableIterator<T>
orElse(CloseableIterator<T> other)
default CloseableIterator<T>
peek(Consumer<? super T> action)
default CloseableIterator<T>
reject(Predicate<? super T> predicate)
default CloseableIterator<T>
replace(T currentElement, T newElement)
default CloseableIterator<T>
replaceAll(T currentElement, T newElement)
default CloseableIterator<T>
retainAll(Iterable<? extends T> elements)
default <U> CloseableIterator<U>
scanLeft(U zero, BiFunction<? super U,? super T,? extends U> operation)
default <U> CloseableIterator<U>
scanRight(U zero, BiFunction<? super T,? super U,? extends U> operation)
default CloseableIterator<io.vavr.collection.Seq<T>>
slideBy(Function<? super T,?> classifier)
default CloseableIterator<io.vavr.collection.Seq<T>>
sliding(int size)
default CloseableIterator<io.vavr.collection.Seq<T>>
sliding(int size, int step)
default CloseableIterator<T>
tail()
default CloseableIterator<T>
take(int n)
default CloseableIterator<T>
takeRight(int n)
default CloseableIterator<T>
takeUntil(Predicate<? super T> predicate)
default CloseableIterator<T>
takeWhile(Predicate<? super T> predicate)
static <T> CloseableIterator<T>
wrapping(io.vavr.collection.Iterator<? extends T> ts)
static <T> CloseableIterator<T>
wrapping(Iterator<? extends T> ts)
static <T> CloseableIterator<T>
wrapping(Iterator<? extends T> iterator, AutoCloseable closeable)
default <U> io.vavr.collection.Iterator<io.vavr.Tuple2<T,U>>
zip(Iterable<? extends U> that)
Deprecated.This method should not be called as it discards the pointers to the closeable resources.default <U> CloseableIterator<io.vavr.Tuple2<T,U>>
zip(CloseableIterator<? extends U> that)
default <U> io.vavr.collection.Iterator<io.vavr.Tuple2<T,U>>
zipAll(Iterable<? extends U> that, T thisElem, U thatElem)
Deprecated.This method should not be called as it discards the pointers to the closeable resources.default <U> CloseableIterator<io.vavr.Tuple2<T,U>>
zipAll(CloseableIterator<? extends U> that, T thisElem, U thatElem)
default <U,R>
io.vavr.collection.Iterator<R>zipWith(Iterable<? extends U> that, BiFunction<? super T,? super U,? extends R> mapper)
Deprecated.This method should not be called as it discards the pointers to the closeable resources.default <U,R>
CloseableIterator<R>zipWith(CloseableIterator<? extends U> that, BiFunction<? super T,? super U,? extends R> mapper)
default CloseableIterator<io.vavr.Tuple2<T,Integer>>
zipWithIndex()
default <U> CloseableIterator<U>
zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
-
Methods inherited from interface io.vavr.collection.Iterator
concat, findLast, foldRight, get, groupBy, hasDefiniteSize, head, initOption, isAsync, isEmpty, isLazy, isSequential, isTraversableAgain, last, length, partition, reduceLeft, reduceRight, scan, span, stringPrefix, tailOption, transform, unzip, unzip3
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, equals, existsUnique, find, foldLeft, forEachWithIndex, hashCode, headOption, isDistinct, isOrdered, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduceLeftOption, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toString, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
-
-
-
Method Detail
-
hasNext
boolean hasNext()
Checks if the iterator contains a next element. If this returns false, the iterator should already be closed: it is not necessary to callclose()
after that.
-
next
T next()
Returns the next element in the stream if there is one available. This may not be called after callingclose()
.
-
close
void close()
Releases all resources underpinning this iterator. Calling this method multiple times is allowed but calling it only once is sufficient. Thenext()
method may not be called after this one is called.- Specified by:
close
in interfaceAutoCloseable
-
of
static <T> CloseableIterator<T> of(T... elements)
-
ofAll
static <T> CloseableIterator<T> ofAll(Iterable<? extends T> ts)
-
empty
static <T> CloseableIterator<T> empty()
-
from
static CloseableIterator<Long> from(long start)
-
wrapping
static <T> CloseableIterator<T> wrapping(io.vavr.collection.Iterator<? extends T> ts)
-
wrapping
static <T> CloseableIterator<T> wrapping(Iterator<? extends T> ts)
-
wrapping
static <T> CloseableIterator<T> wrapping(Iterator<? extends T> iterator, AutoCloseable closeable)
-
collect
default <R> CloseableIterator<R> collect(io.vavr.PartialFunction<? super T,? extends R> partialFunction)
-
concat
default CloseableIterator<T> concat(CloseableIterator<? extends T> that)
-
chop
default io.vavr.collection.Iterator<io.vavr.collection.Iterator<T>> chop(io.vavr.collection.Iterator<Integer> lengths)
Consumes the iterator by splitting it into chunks of the desired length. The returned iterators are not closeable so the parent iterator should be closed directly. Also, the iterators returned should be consumed in the order they are returned if the chunks are intended to be contiguous.- Parameters:
lengths
- the lengths of the desired chunks
-
intersperse
default CloseableIterator<T> intersperse(T element)
- Specified by:
intersperse
in interfaceio.vavr.collection.Iterator<T>
-
zip
@Deprecated default <U> io.vavr.collection.Iterator<io.vavr.Tuple2<T,U>> zip(Iterable<? extends U> that)
Deprecated.This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
-
zip
default <U> CloseableIterator<io.vavr.Tuple2<T,U>> zip(CloseableIterator<? extends U> that)
-
zipWith
@Deprecated default <U,R> io.vavr.collection.Iterator<R> zipWith(Iterable<? extends U> that, BiFunction<? super T,? super U,? extends R> mapper)
Deprecated.This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
-
zipWith
default <U,R> CloseableIterator<R> zipWith(CloseableIterator<? extends U> that, BiFunction<? super T,? super U,? extends R> mapper)
-
zipAll
@Deprecated default <U> io.vavr.collection.Iterator<io.vavr.Tuple2<T,U>> zipAll(Iterable<? extends U> that, T thisElem, U thatElem)
Deprecated.This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
-
zipAll
default <U> CloseableIterator<io.vavr.Tuple2<T,U>> zipAll(CloseableIterator<? extends U> that, T thisElem, U thatElem)
-
zipWithIndex
default CloseableIterator<io.vavr.Tuple2<T,Integer>> zipWithIndex()
-
zipWithIndex
default <U> CloseableIterator<U> zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
-
distinct
default CloseableIterator<T> distinct()
-
distinctBy
default CloseableIterator<T> distinctBy(Comparator<? super T> comparator)
-
distinctBy
default <U> CloseableIterator<T> distinctBy(Function<? super T,? extends U> keyExtractor)
-
drop
default CloseableIterator<T> drop(int n)
-
dropRight
default CloseableIterator<T> dropRight(int n)
-
dropUntil
default CloseableIterator<T> dropUntil(Predicate<? super T> predicate)
-
dropWhile
default CloseableIterator<T> dropWhile(Predicate<? super T> predicate)
-
filter
default CloseableIterator<T> filter(Predicate<? super T> predicate)
-
reject
default CloseableIterator<T> reject(Predicate<? super T> predicate)
-
flatMap
@Deprecated default <U> io.vavr.collection.Iterator<U> flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
Deprecated.This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
-
flatMapCloseable
default <U> CloseableIterator<U> flatMapCloseable(Function<? super T,? extends CloseableIterator<? extends U>> mapper)
-
grouped
default CloseableIterator<io.vavr.collection.Seq<T>> grouped(int size)
-
init
default CloseableIterator<T> init()
-
iterator
default CloseableIterator<T> iterator()
-
map
default <U> CloseableIterator<U> map(Function<? super T,? extends U> mapper)
-
orElse
@Deprecated default io.vavr.collection.Iterator<T> orElse(Iterable<? extends T> other)
Deprecated.This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
-
orElse
default CloseableIterator<T> orElse(CloseableIterator<T> other)
-
orElse
@Deprecated default CloseableIterator<T> orElse(Supplier<? extends Iterable<? extends T>> supplier)
Deprecated.This method should not be called as it discards the pointers to the closeable resources. This will lead to resource leaks.
-
peek
default CloseableIterator<T> peek(Consumer<? super T> action)
-
replace
default CloseableIterator<T> replace(T currentElement, T newElement)
-
replaceAll
default CloseableIterator<T> replaceAll(T currentElement, T newElement)
-
retainAll
default CloseableIterator<T> retainAll(Iterable<? extends T> elements)
-
scanLeft
default <U> CloseableIterator<U> scanLeft(U zero, BiFunction<? super U,? super T,? extends U> operation)
-
scanRight
default <U> CloseableIterator<U> scanRight(U zero, BiFunction<? super T,? super U,? extends U> operation)
-
slideBy
default CloseableIterator<io.vavr.collection.Seq<T>> slideBy(Function<? super T,?> classifier)
-
sliding
default CloseableIterator<io.vavr.collection.Seq<T>> sliding(int size)
-
sliding
default CloseableIterator<io.vavr.collection.Seq<T>> sliding(int size, int step)
-
tail
default CloseableIterator<T> tail()
-
take
default CloseableIterator<T> take(int n)
-
takeRight
default CloseableIterator<T> takeRight(int n)
-
takeUntil
default CloseableIterator<T> takeUntil(Predicate<? super T> predicate)
-
-