public abstract class IteratorUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Function<Enum,String> |
ENUM_NAME
Function for converting Enum to String
|
Constructor and Description |
---|
IteratorUtil() |
Modifier and Type | Method and Description |
---|---|
static <C extends Collection<T>,T> |
addToCollection(Iterable<T> iterable,
C collection)
Adds all the items in
iterator to collection . |
static <C extends Collection<T>,T> |
addToCollection(Iterator<T> iterator,
C collection)
Adds all the items in
iterator to collection . |
static <C extends Collection<Integer>> |
addToCollection(org.neo4j.collection.primitive.PrimitiveIntIterator iterator,
C collection)
Adds all the items in
iterator to collection . |
static <C extends Collection<Long>> |
addToCollection(org.neo4j.collection.primitive.PrimitiveLongIterator 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> Collection<T> |
asCollection(Iterable<T> iterable)
Creates a collection from an iterable.
|
static <T> Collection<T> |
asCollection(Iterator<T> iterable) |
static <E extends Enum<E>> |
asEnumNameSet(Class<E> clazz)
Converts an enum class to to
Set of the names of all valid enum values |
static Set<String> |
asEnumNameSet(Iterable<Enum> enums)
|
static ClosableIterable<String> |
asIterable(File file,
String encoding)
Creates an
Iterable for iterating over the lines of a text file. |
static <T> Iterable<T> |
asIterable(Iterator<T> iterator)
Exposes
iterator as an Iterable . |
static Iterable<Long> |
asIterable(long... array) |
static <T> Iterable<T> |
asIterable(T... array) |
static ClosableIterator<String> |
asIterator(File file,
String encoding)
Creates an
Iterator for iterating over the lines of a text file. |
static <T> Iterator<T> |
asIterator(int maxItems,
T... array) |
static Iterator<Long> |
asIterator(long... array) |
static <T> List<T> |
asList(Iterable<T> iterator) |
static <T> List<T> |
asList(Iterator<T> iterator) |
static List<Integer> |
asList(org.neo4j.collection.primitive.PrimitiveIntIterator iterator) |
static List<Long> |
asList(org.neo4j.collection.primitive.PrimitiveLongIterator iterator) |
static <T> ResourceIterator<T> |
asResourceIterator(Iterator<T> iterator) |
static <T> Set<T> |
asSet(Iterable<T> iterable)
|
static <T> Set<T> |
asSet(Iterator<T> iterator) |
static Set<Integer> |
asSet(org.neo4j.collection.primitive.PrimitiveIntIterator iterator) |
static Set<Long> |
asSet(org.neo4j.collection.primitive.PrimitiveLongIterator iterator) |
static <T> Set<T> |
asSet(T... items)
Creates a
Set from an array of items. |
static <T> Set<T> |
asUniqueSet(Iterable<T> iterable)
|
static <T> Set<T> |
asUniqueSet(Iterator<T> items)
Creates a
Set from an array of items. |
static Set<Long> |
asUniqueSet(org.neo4j.collection.primitive.PrimitiveLongIterator iterator)
Creates a
Set from an array of iterator. |
static <T> Set<T> |
asUniqueSet(T... items)
Creates a
Set from an array of items. |
static <T extends CloneableInPublic> |
cloned(Iterable<T> items,
Class<T> itemClass) |
static <T> boolean |
contains(Iterator<T> iterator,
T item) |
static <T> int |
count(Iterable<T> iterable)
Counts the number of items in the
iterable by looping through it. |
static <T> int |
count(Iterator<T> iterator)
Counts the number of items in the
iterator by looping
through it. |
static <T> ResourceIterator<T> |
emptyIterator() |
static <T> List<T> |
emptyListOf(Class<T> type) |
static <T> Set<T> |
emptySetOf(Class<T> type) |
static <T> T |
first(Iterable<T> iterable)
Returns the given iterable's first element.
|
static <T> T |
first(Iterator<T> iterator)
Returns the given iterator's first element.
|
static <T> T |
firstOrNull(Iterable<T> iterable)
Returns the given iterable's first element or
null if no
element found. |
static <T> T |
firstOrNull(Iterator<T> iterator)
Returns the given iterator's first element or
null if no
element found. |
static <T> T |
fromEnd(Iterable<T> iterable,
int n)
Returns the iterator's n:th item from the end of the iteration.
|
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 boolean |
iteratorsEqual(Iterator<?> first,
Iterator<?> other)
Iterates over the full iterators, and checks equality for each item in them.
|
static <T> T |
last(Iterable<T> iterable)
Returns the given iterable's last element.
|
static <T> T |
last(Iterator<T> iterator)
Returns the given iterator'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> 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 List<Long> |
primitivesList(org.neo4j.collection.primitive.PrimitiveLongIterator iterator) |
static <T> ResourceIterator<T> |
resourceIterator(Iterator<T> iterator,
Resource resource) |
static org.neo4j.kernel.impl.util.PrimitiveLongResourceIterator |
resourceIterator(org.neo4j.collection.primitive.PrimitiveLongIterator iterator,
Resource resource) |
static <T> Set<T> |
set(T... items)
Alias for asSet()
|
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
null if no
element found. |
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(Iterable<T> iterable)
Returns the given iterable's single element or
null 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 Iterator<Long> |
toJavaIterator(org.neo4j.collection.primitive.PrimitiveLongIterator primIterator) |
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.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.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)
public static <T> T firstOrNull(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 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.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.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)
null
if no
element found. If there is more than one element in the iterable a
NoSuchElementException
will be thrown.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(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.T
- the type of elements in iterator
.iterator
- the Iterator
to get elements from.iterator
, or itemIfNone
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(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<Long>> C addToCollection(org.neo4j.collection.primitive.PrimitiveLongIterator iterator, C collection)
iterator
to collection
.C
- the type of Collection
to add to items to.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<Integer>> C addToCollection(org.neo4j.collection.primitive.PrimitiveIntIterator iterator, C collection)
iterator
to collection
.C
- the type of Collection
to add to items to.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 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 <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> int count(Iterator<T> iterator)
iterator
by looping
through it.T
- the type of items in the iterator.iterator
- the Iterator
to count items in.iterator
.public static <T> int count(Iterable<T> iterable)
iterable
by looping through it.T
- the type of items in the iterator.iterable
- the Iterable
to count items in.iterator
.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> Collection<T> asCollection(Iterator<T> iterable)
public static List<Long> asList(org.neo4j.collection.primitive.PrimitiveLongIterator iterator)
public static List<Integer> asList(org.neo4j.collection.primitive.PrimitiveIntIterator iterator)
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> Set<T> asSet(T... items)
Set
from an array of items.items
- the items to add to the set.Set
containing the items.@SafeVarargs public static <T> Set<T> set(T... items)
@SafeVarargs public static <T> Set<T> asUniqueSet(T... items)
Set
from an array of items.items
- 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.items
- the items to add to the set.Set
containing the items.public static Set<String> asEnumNameSet(Iterable<Enum> enums)
enums
- the enums to convert.public static <E extends Enum<E>> Set<String> asEnumNameSet(Class<E> clazz)
Set
of the names of all valid enum valuesE
- enum type boundclazz
- enum classpublic static ClosableIterable<String> asIterable(File file, String encoding)
Iterable
for iterating over the lines of a text file.file
- the file to get the lines for.Iterable
for iterating over the lines of a text file.public static ClosableIterator<String> asIterator(File file, String encoding) throws IOException
Iterator
for iterating over the lines of a text file.
The opened file is closed if an exception occurs during reading or when
the files has been read through all the way.file
- the file to get the lines for.encoding
- to be used for reading the fileIterator
for iterating over the lines of a text file.IOException
@SafeVarargs public static <T> Iterable<T> asIterable(T... array)
@SafeVarargs public static <T> Iterator<T> asIterator(int maxItems, T... array)
@SafeVarargs public static <T> Iterator<T> iterator(T... items)
@SafeVarargs public static <T> Iterator<T> iterator(int maxItems, T... items)
public static <T> ResourceIterator<T> emptyIterator()
public static <T> boolean contains(Iterator<T> iterator, T item)
public static <T extends CloneableInPublic> Iterable<T> cloned(Iterable<T> items, Class<T> itemClass)
public static <T> ResourceIterator<T> asResourceIterator(Iterator<T> iterator)
public static Iterator<Long> toJavaIterator(org.neo4j.collection.primitive.PrimitiveLongIterator primIterator)
public static List<Long> primitivesList(org.neo4j.collection.primitive.PrimitiveLongIterator iterator)
public static Set<Integer> asSet(org.neo4j.collection.primitive.PrimitiveIntIterator iterator)
public static Set<Long> asUniqueSet(org.neo4j.collection.primitive.PrimitiveLongIterator iterator)
Set
from an array of iterator.iterator
- the iterator to add to the set.Set
containing the iterator.public static org.neo4j.kernel.impl.util.PrimitiveLongResourceIterator resourceIterator(org.neo4j.collection.primitive.PrimitiveLongIterator iterator, Resource resource)
public static <T> ResourceIterator<T> resourceIterator(Iterator<T> iterator, Resource resource)
Copyright © 2002–2014 The Neo4j Graph Database Project. All rights reserved.