- See Also:
-
ExtendedIteratorClosableIteratorIter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <X,C extends Collection<X>>
CPuts all the remaining items of the given iterator into thecollection, and returns this collection itself.static <X> booleanReturns whether all elements of the given iterator match the provided predicate.static <X> booleanReturns whether any elements of the given iterator match the provided predicate.static <X> Spliterator<X>asSpliterator(Iterator<? extends X> iterator, long size, int characteristics) Creates aSpliteratorusing a givenIteratoras the source of elements.static <X> Stream<X>Creates a new sequentialStreamfrom the givenIterator, which is expected to deliver nonnull items: it is required that the operationIterator.next()must not returnnullif the methodIterator.hasNext()answerstrue.static <X> Stream<X>Constructs a new sequentialStreamfrom the givenIterator, with the specifiedcharacteristics.static <X> Stream<X>Constructs a new sequentialStreamfrom the givenIterator, with the specifiedcharacteristicsand estimatedsize.static <X> Stream<X>asStream(org.apache.jena.util.iterator.ExtendedIterator<? extends X> iterator) Creates a new sequentialStreamfrom the givenExtendedIterator.static voidCloses iterator if it isCloseableIterator.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>concat(org.apache.jena.util.iterator.ExtendedIterator<? extends X>... iterators) Creates a lazily concatenatedExtended Iteratorwhose elements are all the elements of the given iterators.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>concat(org.apache.jena.util.iterator.ExtendedIterator<? extends X> a, org.apache.jena.util.iterator.ExtendedIterator<? extends X> b) Creates a lazily concatenatedExtended Iteratorwhose elements are all the elements of the first iterator followed by all the elements of the second iterator.static longReturns the count of elements in the given iterator.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>create(Collection<? extends X> members) Creates a newExtended Iterator} over all elements of the specified collection.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>Creates a newExtended Iteratorover all elements of an iterator which will be created by theprovideron first iteration.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>Answers anExtendedIteratorreturning the elements of the specifiediterator.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>distinct(org.apache.jena.util.iterator.ExtendedIterator<X> base) Returns anExtended Iteratorconsisting of the distinct elements (according toObject.equals(Object)) of the given iterator.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>Returns an extended iterator consisting of the elements of the specified extended iterator that match the given predicate.static <X> Optional<X>Returns anOptionaldescribing the first element of the iterator, or an emptyOptionalif the iterator is empty.static <T,F> org.apache.jena.util.iterator.ExtendedIterator<T> flatMap(org.apache.jena.util.iterator.ExtendedIterator<F> base, Function<? super F, ? extends Iterator<? extends T>> mapper) Returns anExtended Iteratorconsisting of the results of replacing each element of the givenbaseiterator with the contents of a mapped iterator produced by applying the provided mapping function (map) to each element.static <X> voidPerformsforEach.static <X> Stream<X>Creates aStreamfor a futureSet, which is produced by the factory-parametergetAsSet.static booleanhasAtLeast(Iterator<?> iterator, int n) Answerstrueiff the given iterator has more thannor equal tonelements.static booleanhasExactly(Iterator<?> iterator, int n) Answerstrueiff the given iterator has exactlynelements.static <X> booleanReturns whether no elements of the given iterator match the provided predicate.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>of()Creates a newExtended Iterator} containing nothing.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>of(X item) Creates a newExtended Iterator} containing a single specified element.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>of(X... members) Creates a newExtended Iterator} containing the specified elements.static <X> org.apache.jena.util.iterator.ExtendedIterator<X>Returns anExtended Iteratorconsisting of the elements of the givenbaseiterator, additionally performing the providedactionon each element as elements are consumed from the resulting iterator.static <X> Set<X>Takes the specified number of items from the source iterator.static <X,K, V, M extends Map<K, V>>
MtoMap(Iterator<X> iterator, Function<? super X, ? extends K> keyMapper, Function<? super X, ? extends V> valueMapper, BinaryOperator<V> mergeFunction, Supplier<M> mapSupplier) Returns aMap(of the type ofM) whose keys and values are the result of applying the provided mapping functions to the input elements.
-
Constructor Details
-
Iterators
public Iterators()
-
-
Method Details
-
asStream
public static <X> Stream<X> asStream(org.apache.jena.util.iterator.ExtendedIterator<? extends X> iterator) Creates a new sequentialStreamfrom the givenExtendedIterator. Takes care about degenerate cases empty and single-element iterator.- Type Parameters:
X- anything- Parameters:
iterator-ExtendedIteratorofX-elements- Returns:
- a
StreamofX - See Also:
-
asStream
Creates a new sequentialStreamfrom the givenIterator, which is expected to deliver nonnull items: it is required that the operationIterator.next()must not returnnullif the methodIterator.hasNext()answerstrue. The methodasStream(Iterator, int)with the second parameter equals0can be used to create aStreamfor an iterator that may delivernulls.If the given parameter is
ClosableIterator, remember to callBaseStream.close()explicitly if the iterator is not exhausted (i.e. in caseIterator.hasNext()is stilltrue). It should be done for all short-circuiting terminal operations such asStream.findFirst(),Stream.findAny(),Stream.anyMatch(Predicate)etc.- Type Parameters:
X- the type of iterator-items- Parameters:
iterator-Iteratorthat delivers nonnull elements, cannot benull- Returns:
Stream
-
asStream
Constructs a new sequentialStreamfrom the givenIterator, with the specifiedcharacteristics. If the given parameter isClosableIterator, an explicit call to theBaseStream.close()method is required for all short-circuiting terminal operations.- Type Parameters:
X- the type of iterator-items- Parameters:
iterator-Iterator, theSpliterator's source, notnullcharacteristics-int, characteristics of theSpliterator's source- Returns:
- a non-parallel
Stream, that wraps theiteratorwith the given characteristics
-
asStream
public static <X> Stream<X> asStream(Iterator<? extends X> iterator, long size, int characteristics) Constructs a new sequentialStreamfrom the givenIterator, with the specifiedcharacteristicsand estimatedsize. If the given parameter isClosableIterator, an explicit call to theBaseStream.close()method is required for all short-circuiting terminal operations.- Type Parameters:
X- the type of iterator-items- Parameters:
iterator-Iterator, theSpliterator's source, notnullsize-long, aSpliterator's estimates size, positive number or-1characteristics-int, characteristics of theSpliterator's source- Returns:
- a non-parallel
Stream, that wraps theiteratorwith the given parameters
-
asSpliterator
public static <X> Spliterator<X> asSpliterator(Iterator<? extends X> iterator, long size, int characteristics) Creates aSpliteratorusing a givenIteratoras the source of elements. If thesizeis not-1, the returnedSpliteratorwill report this number as the initialestimated size.- Type Parameters:
X- the type of iterator-items- Parameters:
iterator-Iterator, notnullsize-long, a positive number or-1characteristics-int, characteristics of the spliterator's source- Returns:
Spliterator- Throws:
NullPointerException- if the given iterator isnull
-
fromSet
Creates aStreamfor a futureSet, which is produced by the factory-parametergetAsSet. The producedSetmust not change and must not containnull.- Type Parameters:
X- the type of items- Parameters:
getAsSet-Supplierthat produces aSetofX- Returns:
- distinct sequential
Stream - See Also:
-
flatMap
public static <T,F> org.apache.jena.util.iterator.ExtendedIterator<T> flatMap(org.apache.jena.util.iterator.ExtendedIterator<F> base, Function<? super F, ? extends Iterator<? extends T>> mapper) Returns anExtended Iteratorconsisting of the results of replacing each element of the givenbaseiterator with the contents of a mapped iterator produced by applying the provided mapping function (map) to each element. A functional equivalent ofStream.flatMap(Function), but forExtendedIterators.- Type Parameters:
F- the element type of the base iterator (from)T- the element type of the new iterator (to)- Parameters:
base-ExtendedIteratorwith elements of typeFmapper-Functionmap-function with Object of type ofF(or any super type) as an input, and anIteratorof typeT(or any extended type) as an output- Returns:
- new
ExtendedIteratorof typeF
-
concat
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> concat(org.apache.jena.util.iterator.ExtendedIterator<? extends X> a, org.apache.jena.util.iterator.ExtendedIterator<? extends X> b) Creates a lazily concatenatedExtended Iteratorwhose elements are all the elements of the first iterator followed by all the elements of the second iterator. A functional equivalent ofStream.concat(Stream, Stream), but forExtendedIterators.- Type Parameters:
X- the type of iterator elements- Parameters:
a- the first iteratorb- the second iterator- Returns:
- the concatenation of the two input iterators
- See Also:
-
concat
@SafeVarargs public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> concat(org.apache.jena.util.iterator.ExtendedIterator<? extends X>... iterators) Creates a lazily concatenatedExtended Iteratorwhose elements are all the elements of the given iterators. If the specified array has length equals2, than this method is equivalent to the methodconcat(ExtendedIterator, ExtendedIterator)). AnExtendedIterator-based functional equivalent of the expressionStream#of(Stream, ..., Stream).flatMap(Function.identity()).- Type Parameters:
X- the type of iterator elements- Parameters:
iterators- Array of iterators- Returns:
- all input elements as a single
ExtendedIteratorof typeX - See Also:
-
filter
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> filter(org.apache.jena.util.iterator.ExtendedIterator<X> iterator, Predicate<? super X> predicate) Returns an extended iterator consisting of the elements of the specified extended iterator that match the given predicate. A functional equivalent ofStream.filter(Predicate), but forExtendedIterators.- Type Parameters:
X- the element type of the input and output iterators- Parameters:
iterator-ExtendedIteratorwith elements of typeXpredicate-Predicateto apply to elements of the iterator- Returns:
- a new iterator
-
peek
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> peek(org.apache.jena.util.iterator.ExtendedIterator<X> base, Consumer<? super X> action) Returns anExtended Iteratorconsisting of the elements of the givenbaseiterator, additionally performing the providedactionon each element as elements are consumed from the resulting iterator. A functional equivalent ofStream.peek(Consumer), but forExtendedIterators.- Type Parameters:
X- the element type of the input and output iterators- Parameters:
base-ExtendedIteratorwith elements of typeXaction-Consumeraction- Returns:
- new
ExtendedIteratorof typeX
-
distinct
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> distinct(org.apache.jena.util.iterator.ExtendedIterator<X> base) Returns anExtended Iteratorconsisting of the distinct elements (according toObject.equals(Object)) of the given iterator. A functional equivalent ofStream.distinct(), but forExtendedIterators. Warning: the result is temporary stored in memory!- Type Parameters:
X- the element type of the input and output iterators- Parameters:
base-ExtendedIteratorwith elements of typeX- Returns:
- new
ExtendedIteratorof typeXwithout duplicates
-
anyMatch
Returns whether any elements of the given iterator match the provided predicate. A functional equivalent ofStream.anyMatch(Predicate), but forIterators. -
allMatch
Returns whether all elements of the given iterator match the provided predicate. A functional equivalent ofStream.allMatch(Predicate), but forIterators.- Type Parameters:
X- the element type of the iterator- Parameters:
iterator-Iteratorwith elements of typeXpredicate-Predicateto apply to elements of the iterator- Returns:
trueif either all elements of the iterator match the provided predicate or the iterator is empty, otherwisefalse- See Also:
-
noneMatch
Returns whether no elements of the given iterator match the provided predicate. A functional equivalent ofStream.noneMatch(Predicate), but forIterators.- Type Parameters:
X- the element type of the iterator- Parameters:
iterator-Iteratorwith elements of typeXpredicate-Predicateto apply to elements of the iterator- Returns:
trueif either no elements of the iterator match the provided predicate or the iterator is empty, otherwisefalse- See Also:
-
findFirst
Returns anOptionaldescribing the first element of the iterator, or an emptyOptionalif the iterator is empty. A functional equivalent ofStream.findFirst(), but forIterators. Warning: the method closes the specified iterator, so it is not possible to reuse it after calling this method.- Type Parameters:
X- the element type of the iterator- Parameters:
iterator-Iterator, notnull- Returns:
OptionalofX- Throws:
NullPointerException- if the element selected isnull
-
count
Returns the count of elements in the given iterator. A functional equivalent ofStream.count(), but forIterators. Warning: the method closes the specified iterator, so it is not possible to reuse it after.- Parameters:
iterator-Iterator, notnull- Returns:
- long, the count of elements in the given
iterator
-
hasAtLeast
Answerstrueiff the given iterator has more thannor equal tonelements.- Parameters:
n- positive numberiterator-Iterator, notnull- Returns:
trueif the specified iterator has at leastnelements
-
hasExactly
Answerstrueiff the given iterator has exactlynelements.- Parameters:
n- positive numberiterator-Iterator, notnull- Returns:
trueif the specified iterator has exactlynelements
-
forEach
PerformsforEach. On finish iteration, the iterator will be closed. -
addAll
Puts all the remaining items of the given iterator into thecollection, and returns this collection itself. This is a terminal operation.- Type Parameters:
X- the element type of the iterator, notnullC- theCollectiontype, notnull- Parameters:
source- theIteratorwith elements of typeXtarget- the collection of typeC- Returns:
C, the same instance as specified
-
takeAsSet
Takes the specified number of items from the source iterator. -
toMap
public static <X,K, M toMapV, M extends Map<K, V>> (Iterator<X> iterator, Function<? super X, ? extends K> keyMapper, Function<? super X, ? extends V> valueMapper, BinaryOperator<V> mergeFunction, Supplier<M> mapSupplier) Returns aMap(of the type ofM) whose keys and values are the result of applying the provided mapping functions to the input elements. A functional equivalent ofstream.collect(Collectors.toMap(...)), but for plainIterators. This method makes no guarantees about synchronization or atomicity properties of it.- Type Parameters:
X- the type of the input elementsK- the output type of the key mapping functionV- the output type of the value mapping functionM- the type of the resultingMap- Parameters:
iterator- input elements in the form ofIteratorkeyMapper- a mapping function to produce keysvalueMapper- a mapping function to produce valuesmergeFunction- a merge function, used to resolve collisions between values associated with the same key, as supplied toMap.merge(Object, Object, BiFunction)mapSupplier- a function which returns new, emptyMapinto which the results will be inserted- Returns:
- a
Mapwhose keys are the result of applying a key mapping function to the input elements, and whose values are the result of applying a value mapping function to all input elements equal to the key and combining them using the merge function - See Also:
-
close
Closes iterator if it isCloseableIterator.- Parameters:
iterator-Iterator
-
of
Creates a newExtended Iterator} containing the specified elements.- Type Parameters:
X- the element type of the new iterator- Parameters:
members- Array of elements of the typeX- Returns:
- a fresh
ExtendedIteratorinstance
-
of
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> of()Creates a newExtended Iterator} containing nothing.- Type Parameters:
X- the element type of the new iterator- Returns:
- a fresh
ExtendedIteratorinstance
-
of
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> of(X item) Creates a newExtended Iterator} containing a single specified element.- Type Parameters:
X- the element type of the new iterator- Parameters:
item- - an object of typeX- Returns:
- a fresh
ExtendedIteratorinstance
-
create
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> create(Collection<? extends X> members) Creates a newExtended Iterator} over all elements of the specified collection.- Type Parameters:
X- the element type of the new iterator- Parameters:
members-Collectionof elements of the typeX- Returns:
- a fresh
ExtendedIteratorinstance
-
create
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> create(Iterator<? extends X> iterator) Answers anExtendedIteratorreturning the elements of the specifiediterator. If the giveniteratoris itself anExtendedIterator, return that; otherwise wrapiterator.- Type Parameters:
X- the element type of the iterator- Parameters:
iterator-Iterator, notnull- Returns:
ExtendedIteratorinstance
-
create
public static <X> org.apache.jena.util.iterator.ExtendedIterator<X> create(Supplier<Iterator<? extends X>> provider) Creates a newExtended Iteratorover all elements of an iterator which will be created by theprovideron first iteration. The returned iterator does not contain any elements, but they will be derived at once when calling any of theExtendedIteratormethods.The idea is to provide a truly lazy iterator and, subsequently, a stream (through the
asStream(Iterator)method). When any distinct operation (i.e.distinct(ExtendedIterator)orStream.distinct()) is used, it, in fact, collects on demand an in-memorySetcontaining all elements, but it will be appeared in process and an iterator or a stream initially weighs nothing. This method allows achieving a similar behavior: when creating anExtendedIteratordoes not weight anything, but it materializes itself when processing. Therefore, operations such as(stream-1 + stream-2).findFirst()will demand less memory.The returned iterator is not thread-safe, just as like any other RDF extended iterator we work with.
-