Class Iterables
Resource, it will be closed when the processing
has been completed.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,C extends Collection<T>>
CCollect all the elements available initerableand add them to the providedcollection.static <T> T[]static <T> List<T>Creates a list from an iterable.static <T> org.neo4j.graphdb.ResourceIterable<T>asResourceIterable(Iterable<T> iterable) static <T> Set<T>static <T> longCounts the number of items in theiterableby looping through it.static <T> TReturns the given iterable's first element.static <T> TfirstOrNull(Iterable<T> iterable) Returns the given iterable's first element ornullif no element found.static <T,C extends T>
Iterable<T>iterable(C... items) static <T> TReturns the given iterable's single element.static <T> Stream<T>Create a stream from the given iterable.
-
Constructor Details
-
Iterables
public Iterables()
-
-
Method Details
-
addAll
Collect all the elements available initerableand add them to the providedcollection.If the
iterableimplementsResourceit will beclosedin afinallyblock after all the items have been added.- Type Parameters:
T- the type of elements initerable.C- the type of the collection to add the items to.- Parameters:
collection- the collection to add items to.iterable- the iterable from which items will be collected- Returns:
- the
collectionthat has been updated.
-
iterable
-
asArray
-
asResourceIterable
-
firstOrNull
Returns the given iterable's first element ornullif no element found.If the
iterableimplementsResource, then it will be closed in afinallyblock after the first item has been retrieved, or failed to be retrieved.If the
iteratorcreated by theiterableimplementsResourceit will beclosedin afinallyblock after the single item has been retrieved, or failed to be retrieved.- Type Parameters:
T- the type of elements initerable.- Parameters:
iterable- theIterableto get elements from.- Returns:
- the first element in the
iterable, ornullif no element found.
-
first
Returns the given iterable's first element. If no element is found aNoSuchElementExceptionis thrown.If the
iterableimplementsResource, then it will be closed in afinallyblock after the first item has been retrieved, or failed to be retrieved.- Type Parameters:
T- the type of elements initerable.- Parameters:
iterable- theIterableto get elements from.- Returns:
- the first element in the
iterable. - Throws:
NoSuchElementException- if no element found.
-
single
Returns the given iterable's single element. If there are no elements or more than one element in the iterable aNoSuchElementExceptionwill be thrown.If the
iterableimplementsResource, then it will be closed in afinallyblock after the single item has been retrieved, or failed to be retrieved.If the
iteratorcreated by theiterableimplementsResourceit will beclosedin afinallyblock after the single item has been retrieved, or failed to be retrieved.- Type Parameters:
T- the type of elements initerable.- Parameters:
iterable- theIterableto get elements from.- Returns:
- the single element in the
iterable. - Throws:
NoSuchElementException- if there isn't exactly one element.
-
count
Counts the number of items in theiterableby looping through it.If the
iterableimplementsResource, then it will be closed in afinallyblock after all its items have been counted.If the
iteratorcreated by theiterableimplementsResourceit will beclosedin afinallyblock after the items have been counted.- Type Parameters:
T- the type of items in the iterator.- Parameters:
iterable- theIterableto count items in.- Returns:
- the number of items found in
iterable.
-
asList
Creates a list from an iterable.If the
iterableimplementsResource, then it will be closed in afinallyblock after all its items have been added.If the
iteratorcreated by theiterableimplementsResourceit will beclosedin afinallyblock after all the items have been added.- Type Parameters:
T- The generic type of both the iterable and the list.- Parameters:
iterable- The iterable to create the list from.- Returns:
- a list containing all items from the iterable.
-
asSet
Creates aSetfrom anIterable.If the
iterableimplementsResource, then it will be closed in afinallyblock after all its items have been added.If the
iteratorcreated by theiterableimplementsResourceit will beclosedin afinallyblock after all the items have been added.- Type Parameters:
T- The generic type of items.- Parameters:
iterable- The items to create the set from.- Returns:
- a set containing all items from the
Iterable.
-
stream
Create a stream from the given iterable.Note: returned stream needs to be closed via
BaseStream.close()if the given iterable implementsResource.- Type Parameters:
T- the type of elements in the given iterable- Parameters:
iterable- the iterable to convert to stream- Returns:
- stream over the iterable elements
- Throws:
NullPointerException- when the given iterable isnull
-