public final class Iterables extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T,C extends Collection<T>> |
addAll(C collection,
Iterable<? extends T> iterable) |
static <C extends Collection<T>,T> |
addToCollection(Iterable<T> iterable,
C collection)
Adds all the items in
iterator to collection. |
static <T,C extends T> |
append(C item,
Iterable<T> iterable) |
static <T> T[] |
asArray(Class<T> componentType,
Iterable<T> iterable) |
static Object[] |
asArray(Iterable<Object> iterable) |
static <T> Collection<T> |
asCollection(Iterable<T> iterable)
Creates a collection from an iterable.
|
static Iterable<Integer> |
asIterable(int... array) |
static Iterable<Long> |
asIterable(long... array) |
static <T> Iterable<T> |
asIterable(T... array) |
static <T> List<T> |
asList(Iterable<T> iterator) |
static <T,U> Map<T,U> |
asMap(Iterable<Pair<T,U>> pairs) |
static <T> org.neo4j.graphdb.ResourceIterable<T> |
asResourceIterable(Iterable<T> iterable) |
static <T> Set<T> |
asSet(Iterable<T> iterable)
|
static <T> Set<T> |
asUniqueSet(Iterable<T> iterable)
|
static <T> Iterable<T> |
cache(Iterable<T> iterable) |
static <T,C> Iterable<T> |
cast(Iterable<C> iterable) |
static <T> Iterable<T> |
concat(Iterable<? extends T>... iterables) |
static <T> Iterable<T> |
concat(Iterable<Iterable<T>> iterables) |
static <T> long |
count(Iterable<T> iterable)
Counts the number of items in the
iterator by looping
through it. |
static <T> long |
count(Iterable<T> iterable,
Predicate<T> filter)
Counts the number of filtered items in the
iterable by looping through it. |
static <T> Iterable<T> |
empty() |
static <T> Iterable<T> |
emptyResourceIterable() |
static <T extends Enum<T>> |
enumNames(Class<T> cls) |
static <X> Iterable<X> |
filter(Predicate<? super X> specification,
Iterable<X> i) |
static <T> T |
first(Iterable<T> iterable)
Returns the given iterable's first element.
|
static <T> T |
firstOrNull(Iterable<T> iterable)
Returns the given iterable's first element or
null if no
element found. |
static <FROM,TO> Iterable<TO> |
flatMap(Function<? super FROM,? extends Iterable<TO>> function,
Iterable<FROM> from) |
static <X,I extends Iterable<? extends X>> |
flatten(I... multiIterator) |
static <X,S extends Iterable<? extends X>,I extends Iterable<S>> |
flattenIterable(I multiIterator) |
static <T> T |
fromEnd(Iterable<T> iterable,
int n)
Returns the iterator's n:th item from the end of the iteration.
|
static <T> int |
indexOf(T itemToFind,
Iterable<T> iterable)
Returns the index of the first occurrence of the specified element
in this iterable, or -1 if this iterable does not contain the element.
|
static <T,C extends T> |
iterable(C... items) |
static String |
join(String joinString,
Iterable<?> iter) |
static <T> T |
last(Iterable<T> iterable)
Returns the given iterable's last element.
|
static <T> T |
lastOrNull(Iterable<T> iterable)
Returns the given iterable's last element or
null if no
element found. |
static <T> Function<Iterable<T>,Iterable<T>> |
limit(int limitItems) |
static <T> Iterable<T> |
limit(int limitItems,
Iterable<T> iterable) |
static <FROM,TO> Iterable<TO> |
map(Function<? super FROM,? extends TO> function,
Iterable<FROM> from) |
static <T> Iterable<T> |
mix(Iterable<T>... iterables) |
static <T> Iterable<T> |
option(T item) |
static <T,C extends T> |
prepend(C item,
Iterable<T> iterable) |
static <T> org.neo4j.graphdb.ResourceIterable<T> |
resourceIterable(Iterable<T> iterable) |
static <X> Iterable<X> |
reverse(Iterable<X> iterable) |
static <T> T |
single(Iterable<T> iterable)
Returns the given iterable's single element.
|
static <T> T |
single(Iterable<T> iterable,
T itemIfNone)
Returns the given iterable's single element or
itemIfNone if no
element found. |
static <T> T |
singleOrNull(Iterable<T> iterable)
Returns the given iterable's single element or
null if no
element found. |
static <X> Iterable<X> |
skip(int skip,
Iterable<X> iterable) |
static <T,S extends Comparable> |
sort(Iterable<T> iterable,
Function<T,S> compareFunction) |
static <T> Stream<T> |
stream(Iterable<T> iterable)
Create a stream from the given iterable.
|
static <T> Stream<T> |
stream(Iterable<T> iterable,
int characteristics)
Create a stream from the given iterable with given characteristics.
|
static String |
toString(Iterable<?> values,
String separator) |
static <T> Iterable<T> |
unique(Iterable<T> iterable) |
public static <T> Iterable<T> empty()
public static <T> Iterable<T> emptyResourceIterable()
public static <T,C extends Collection<T>> C addAll(C collection, Iterable<? extends T> iterable)
@SafeVarargs public static <X,I extends Iterable<? extends X>> Iterable<X> flatten(I... multiIterator)
public static <X,S extends Iterable<? extends X>,I extends Iterable<S>> Iterable<X> flattenIterable(I multiIterator)
@SafeVarargs public static <T> Iterable<T> mix(Iterable<T>... iterables)
public static <FROM,TO> Iterable<TO> map(Function<? super FROM,? extends TO> function, Iterable<FROM> from)
public static <FROM,TO> Iterable<TO> flatMap(Function<? super FROM,? extends Iterable<TO>> function, Iterable<FROM> from)
@SafeVarargs public static <T,C extends T> Iterable<T> iterable(C... items)
@SafeVarargs public static <T> Iterable<T> concat(Iterable<? extends T>... iterables)
public static <T> org.neo4j.graphdb.ResourceIterable<T> asResourceIterable(Iterable<T> iterable)
public static <T> T firstOrNull(Iterable<T> iterable)
null if no
element found.
If the iterator created by the iterable 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 iterable.iterable - the Iterable to get elements from.iterable, or null if no
element found.public static <T> T first(Iterable<T> iterable)
NoSuchElementException is thrown.T - the type of elements in iterable.iterable - the Iterable to get elements from.iterable.NoSuchElementException - if no element found.public static <T> T lastOrNull(Iterable<T> iterable)
null if no
element found.T - the type of elements in iterable.iterable - the Iterable to get elements from.iterable, or null if no
element found.public static <T> T last(Iterable<T> iterable)
NoSuchElementException is thrown.T - the type of elements in iterable.iterable - the Iterable to get elements from.iterable.NoSuchElementException - if no element found.public static <T> T singleOrNull(Iterable<T> iterable)
null if no
element found. If there is more than one element in the iterable a
NoSuchElementException will be thrown.
If the iterator created by the iterable 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 iterable.iterable - the Iterable to get elements from.iterable, or null if no
element found.NoSuchElementException - if more than one element was found.public static <T> T single(Iterable<T> iterable)
NoSuchElementException
will be thrown.
If the iterator created by the iterable 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 iterable.iterable - the Iterable to get elements from.iterable.NoSuchElementException - if there isn't exactly one element.public static <T> T single(Iterable<T> iterable, T itemIfNone)
itemIfNone if no
element found. If there is more than one element in the iterable a
NoSuchElementException will be thrown.
If the iterator created by the iterable 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 iterable.iterable - the Iterable to get elements from.itemIfNone - item to use if none is founditerable, or null if no
element found.NoSuchElementException - if more than one element was found.public static <T> T fromEnd(Iterable<T> iterable, int n)
NoSuchElementException is thrown.T - the type of elements in iterator.iterable - the Iterable 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 <C extends Collection<T>,T> C addToCollection(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> long count(Iterable<T> iterable)
iterator by looping
through it.T - the type of items in the iterator.iterable - the Iterable to count items in.iterable.public static <T> long count(Iterable<T> iterable, Predicate<T> filter)
iterable by looping through it.T - the type of items in the iterator.iterable - the Iterable to count items in.filter - the filter to test items againstiterable.public static <T> Collection<T> asCollection(Iterable<T> iterable)
T - The generic type of both the iterable and the collection.iterable - The iterable to create the collection from.public static <T> Set<T> asSet(Iterable<T> iterable)
T - The generic type of items.iterable - The items to create the set from.Iterable.public static <T> Set<T> asUniqueSet(Iterable<T> iterable)
T - The generic type of items.iterable - The items to create the set from.Iterable.@SafeVarargs public static <T> Iterable<T> asIterable(T... array)
public static <T> org.neo4j.graphdb.ResourceIterable<T> resourceIterable(Iterable<T> iterable)
public static <T> int indexOf(T itemToFind,
Iterable<T> iterable)
T - the type of the elementsitemToFind - element to finditerable - iterable to look for the element innull if that was specified) or -1public static <T> Iterable<T> option(T item)
public static <T,S extends Comparable> Iterable<T> sort(Iterable<T> iterable, Function<T,S> compareFunction)
public static <T> Stream<T> stream(Iterable<T> iterable)
Note: returned stream needs to be closed via BaseStream.close() if the given iterable implements
Resource.
T - the type of elements in the given iterableiterable - the iterable to convert to streamNullPointerException - when the given iterable is nullpublic static <T> Stream<T> stream(Iterable<T> iterable, int characteristics)
Note: returned stream needs to be closed via BaseStream.close() if the given iterable implements
Resource.
T - the type of elements in the given iterableiterable - the iterable to convert to streamcharacteristics - the logical OR of characteristics for the underlying SpliteratorNullPointerException - when the given iterable is nullCopyright © 2002–2018 The Neo4j Graph Database Project. All rights reserved.