public abstract class Iterators extends Object
| Constructor and Description |
|---|
Iterators() |
| Modifier and Type | Method and Description |
|---|---|
static <C extends Collection<T>,T> |
addToCollection(Iterator<T> iterator,
C collection)
Adds all the items in
iterator to collection. |
static <C extends Collection<T>,T> |
addToCollectionUnique(Iterable<T> iterable,
C collection)
Adds all the items in
iterator to collection. |
static <C extends Collection<T>,T> |
addToCollectionUnique(Iterator<T> iterator,
C collection)
Adds all the items in
iterator to collection. |
static <T> T[] |
array(T... items) |
static <T> Collection<T> |
asCollection(Iterator<T> iterable) |
static <T> Iterable<T> |
asIterable(Iterator<T> iterator)
Exposes
iterator as an Iterable. |
static Iterator<Integer> |
asIterator(int... array) |
static <T> Iterator<T> |
asIterator(int maxItems,
T... array) |
static Iterator<Long> |
asIterator(long... array) |
static <T> List<T> |
asList(Iterator<T> iterator) |
static <T,EX extends Exception> |
asList(org.neo4j.collection.RawIterator<T,EX> iterator) |
static <T,EX extends Exception> |
asRawIterator(Iterator<T> iter) |
static <T> org.neo4j.graphdb.ResourceIterable<T> |
asResourceIterable(org.neo4j.graphdb.ResourceIterator<T> it) |
static <T> org.neo4j.graphdb.ResourceIterator<T> |
asResourceIterator(Iterator<T> iterator) |
static <T> Set<T> |
asSet(Iterator<T> iterator) |
static <T> Set<T> |
asSet(T... items)
Creates a
Set from an array of items.an |
static <T> Set<T> |
asUniqueSet(Iterator<T> items)
Creates a
Set from an array of items. |
static <T> Set<T> |
asUniqueSet(T... items)
Creates a
Set from an array of items. |
static <T> Iterator<T> |
concat(Iterator<? extends T>... iterators) |
static <T> Iterator<T> |
concat(Iterator<Iterator<T>> iterators) |
static <T> org.neo4j.graphdb.ResourceIterator<T> |
concatResourceIterators(Iterator<org.neo4j.graphdb.ResourceIterator<T>> iterators) |
static <T> boolean |
contains(Iterator<T> iterator,
T item) |
static <T> long |
count(Iterator<T> iterator) |
static <T> long |
count(Iterator<T> iterator,
Predicate<T> filter)
Counts the number of filtered in the
iterator by looping
through it. |
static <T> org.neo4j.graphdb.ResourceIterator<T> |
emptyResourceIterator() |
static <X> Iterator<X> |
filter(Predicate<? super X> specification,
Iterator<X> i) |
static <T> T |
first(Iterator<T> iterator)
Returns the given iterator's first element.
|
static <T> T |
firstOrNull(Iterator<T> iterator)
Returns the given iterator's first element or
null if no
element found. |
static <FROM,TO> Iterator<TO> |
flatMap(Function<? super FROM,? extends Iterator<TO>> function,
Iterator<FROM> from) |
static <T> T |
fromEnd(Iterator<T> iterator,
int n)
Returns the iterator's n:th item from the end of the iteration.
|
static <T> T |
fromEndOrNull(Iterator<T> iterator,
int n)
Returns the iterator's n:th item from the end of the iteration.
|
static <T> Iterator<T> |
iterator(int maxItems,
T... items) |
static <T> Iterator<T> |
iterator(T... items) |
static <T> Iterator<T> |
iterator(T item) |
static boolean |
iteratorsEqual(Iterator<?> first,
Iterator<?> other)
Iterates over the full iterators, and checks equality for each item in them.
|
static String |
join(String joinString,
Iterator<?> iter) |
static <T> T |
last(Iterator<T> iterator)
Returns the given iterator's last element.
|
static <T> T |
lastOrNull(Iterator<T> iterator)
Returns the given iterator's last element or
null if no
element found. |
static <T> Iterable<T> |
loop(Iterator<T> iterator)
Convenience method for looping over an
Iterator. |
static <FROM,TO> Iterator<TO> |
map(Function<? super FROM,? extends TO> function,
Iterator<FROM> from) |
static <FROM,TO,EX extends Exception> |
map(org.neo4j.function.ThrowingFunction<? super FROM,? extends TO,EX> function,
org.neo4j.collection.RawIterator<FROM,EX> from) |
static <T> PrefetchingIterator<T> |
prefetching(Iterator<T> iterator) |
static <T> org.neo4j.graphdb.ResourceIterator<T> |
resourceIterator(Iterator<T> iterator,
org.neo4j.graphdb.Resource resource) |
static <T> Set<T> |
set(T... items)
Alias for asSet()
|
static <T> T |
single(Iterator<T> iterator)
Returns the given iterator's single element.
|
static <T> T |
single(Iterator<T> iterator,
T itemIfNone)
Returns the given iterator's single element or
itemIfNone if no
element found. |
static <T> T |
singleOrNull(Iterator<T> iterator)
Returns the given iterator's single element or
null if no
element found. |
static <T> Stream<T> |
stream(Iterator<T> iterator)
Create a stream from the given iterator.
|
static <T> Stream<T> |
stream(Iterator<T> iterator,
int characteristics)
Create a stream from the given iterator with given characteristics.
|
public static <T> T firstOrNull(Iterator<T> iterator)
null if no
element found.T - the type of elements in iterator.iterator - the Iterator to get elements from.iterator, or null if no
element found.public static <T> T first(Iterator<T> iterator)
NoSuchElementException is thrown.T - the type of elements in iterator.iterator - the Iterator to get elements from.iterator.NoSuchElementException - if no element found.public static <T> T lastOrNull(Iterator<T> iterator)
null if no
element found.T - the type of elements in iterator.iterator - the Iterator to get elements from.iterator, or null if no
element found.public static <T> T last(Iterator<T> iterator)
NoSuchElementException is thrown.T - the type of elements in iterator.iterator - the Iterator to get elements from.iterator.NoSuchElementException - if no element found.public static <T> T singleOrNull(Iterator<T> iterator)
null if no
element found. If there is more than one element in the iterator a
NoSuchElementException will be thrown.
If the iterator implements Resource it will be closed
in a finally block after the single item has been retrieved, or failed to be retrieved.T - the type of elements in iterator.iterator - the Iterator to get elements from.iterator, or null if no
element found.NoSuchElementException - if more than one element was found.public static <T> T single(Iterator<T> iterator)
NoSuchElementException
will be thrown.
If the iterator implements Resource it will be closed
in a finally block after the single item has been retrieved, or failed to be retrieved.T - the type of elements in iterator.iterator - the Iterator to get elements from.iterator.NoSuchElementException - if there isn't exactly one element.public static <T> T fromEnd(Iterator<T> iterator, int n)
NoSuchElementException is thrown.T - the type of elements in iterator.iterator - the Iterator to get elements from.n - the n:th item from the end to get.NoSuchElementException - if the iterator contains less than n-1 items.public static <T> T fromEndOrNull(Iterator<T> iterator, int n)
null is returned.T - the type of elements in iterator.iterator - the Iterator to get elements from.n - the n:th item from the end to get.null if the iterator doesn't contain that many items.public static boolean iteratorsEqual(Iterator<?> first, Iterator<?> other)
first - the first iteratorother - the other iteratortrue if all items are equal; otherwisepublic static <T> T single(Iterator<T> iterator, T itemIfNone)
itemIfNone if no
element found. If there is more than one element in the iterator a
NoSuchElementException will be thrown.
If the iterator implements Resource it will be closed
in a finally block after the single item has been retrieved, or failed to be retrieved.T - the type of elements in iterator.iterator - the Iterator to get elements from.itemIfNone - item to use if none is founditerator, or itemIfNone if no
element found.NoSuchElementException - if more than one element was found.public static <C extends Collection<T>,T> C addToCollection(Iterator<T> iterator, C collection)
iterator to collection.C - the type of Collection to add to items to.T - the type of items in the collection and iterator.iterator - the Iterator to grab the items from.collection - the Collection to add the items to.collection which was passed in, now filled
with the items from iterator.public static <C extends Collection<T>,T> C addToCollectionUnique(Iterator<T> iterator, C collection)
iterator to collection.C - the type of Collection to add to items to.T - the type of items in the collection and iterator.iterator - the Iterator to grab the items from.collection - the Collection to add the items to.collection which was passed in, now filled
with the items from iterator.public static <C extends Collection<T>,T> C addToCollectionUnique(Iterable<T> iterable, C collection)
iterator to collection.C - the type of Collection to add to items to.T - the type of items in the collection and iterator.iterable - the Iterator to grab the items from.collection - the Collection to add the items to.collection which was passed in, now filled
with the items from iterator.public static <T> Iterable<T> loop(Iterator<T> iterator)
Iterator. Converts the
Iterator to an Iterable by wrapping it in an
Iterable that returns the Iterator. It breaks the
contract of Iterable in that it returns the supplied iterator
instance for each call to iterator() on the returned
Iterable instance. This method exists to make it easy to use an
Iterator in a for-loop.public static <T> long count(Iterator<T> iterator)
public static <T> long count(Iterator<T> iterator, Predicate<T> filter)
iterator by looping
through it.T - the type of items in the iterator.iterator - the Iterator to count items in.filter - the filter to test items againstiterator.public static <T> Collection<T> asCollection(Iterator<T> iterable)
public static <T,EX extends Exception> List<T> asList(org.neo4j.collection.RawIterator<T,EX> iterator) throws EX extends Exception
EX extends Exception@SafeVarargs public static <T> Set<T> asSet(T... items)
Set from an array of items.anT - the type of the itemsitems - the items to add to the set.Set containing the items.@SafeVarargs public static <T> Set<T> set(T... items)
T - the type of the itemsitems - the items to add to the set.Set containing the items.@SafeVarargs public static <T> Set<T> asUniqueSet(T... items)
Set from an array of items.T - the type of the itemsitems - the items to add to the set.Set containing the items.public static <T> Set<T> asUniqueSet(Iterator<T> items)
Set from an array of items.T - the type of the itemsitems - the items to add to the set.Set containing the items.@SafeVarargs public static <T> Iterator<T> asIterator(int maxItems, T... array)
public static <T> Iterator<T> iterator(T item)
@SafeVarargs public static <T> Iterator<T> iterator(T... items)
@SafeVarargs public static <T> Iterator<T> iterator(int maxItems, T... items)
public static <T> org.neo4j.graphdb.ResourceIterator<T> emptyResourceIterator()
public static <T> boolean contains(Iterator<T> iterator, T item)
public static <T> org.neo4j.graphdb.ResourceIterator<T> asResourceIterator(Iterator<T> iterator)
public static <T> org.neo4j.graphdb.ResourceIterator<T> resourceIterator(Iterator<T> iterator, org.neo4j.graphdb.Resource resource)
@SafeVarargs public static <T> T[] array(T... items)
public static <FROM,TO> Iterator<TO> map(Function<? super FROM,? extends TO> function, Iterator<FROM> from)
public static <FROM,TO,EX extends Exception> org.neo4j.collection.RawIterator<TO,EX> map(org.neo4j.function.ThrowingFunction<? super FROM,? extends TO,EX> function, org.neo4j.collection.RawIterator<FROM,EX> from)
public static <T,EX extends Exception> org.neo4j.collection.RawIterator<T,EX> asRawIterator(Iterator<T> iter)
public static <FROM,TO> Iterator<TO> flatMap(Function<? super FROM,? extends Iterator<TO>> function, Iterator<FROM> from)
@SafeVarargs public static <T> Iterator<T> concat(Iterator<? extends T>... iterators)
public static <T> org.neo4j.graphdb.ResourceIterator<T> concatResourceIterators(Iterator<org.neo4j.graphdb.ResourceIterator<T>> iterators)
public static <T> org.neo4j.graphdb.ResourceIterable<T> asResourceIterable(org.neo4j.graphdb.ResourceIterator<T> it)
public static <T> PrefetchingIterator<T> prefetching(Iterator<T> iterator)
public static <T> Stream<T> stream(Iterator<T> iterator)
Note: returned stream needs to be closed via BaseStream.close() if the given iterator implements
Resource.
T - the type of elements in the given iteratoriterator - the iterator to convert to streamNullPointerException - when the given stream is nullpublic static <T> Stream<T> stream(Iterator<T> iterator, int characteristics)
Note: returned stream needs to be closed via BaseStream.close() if the given iterator implements
Resource.
T - the type of elements in the given iteratoriterator - the iterator to convert to streamcharacteristics - the logical OR of characteristics for the underlying SpliteratorNullPointerException - when the given iterator is nullCopyright © 2002–2018 The Neo4j Graph Database Project. All rights reserved.