|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.neo4j.helpers.collection.IteratorUtil
public abstract class IteratorUtil
Contains common functionality regarding Iterator
s and
Iterable
s.
Constructor Summary | |
---|---|
IteratorUtil()
|
Method Summary | ||
---|---|---|
static
|
addToCollection(Iterable<T> iterable,
C collection)
Adds all the items in iterator to collection . |
|
static
|
addToCollection(Iterator<T> iterator,
C collection)
Adds all the items in iterator to collection . |
|
static
|
asCollection(Iterable<T> iterable)
Creates a collection from an iterable. |
|
static ClosableIterable<String> |
asIterable(File file)
Creates an Iterable for iterating over the lines of a text file. |
|
static
|
asIterable(Iterator<T> iterator)
Exposes iterator as an Iterable . |
|
static ClosableIterator<String> |
asIterator(File file)
Creates an Iterator for iterating over the lines of a text file. |
|
static
|
count(Iterable<T> iterable)
Counts the number of items in the iterable by looping through it. |
|
static
|
count(Iterator<T> iterator)
Counts the number of items in the iterator by looping
through it. |
|
static
|
first(Iterable<T> iterable)
Returns the given iterable's first element. |
|
static
|
first(Iterator<T> iterator)
Returns the given iterator's first element. |
|
static
|
firstOrNull(Iterable<T> iterable)
Returns the given iterable's first element or null if no
element found. |
|
static
|
firstOrNull(Iterator<T> iterator)
Returns the given iterator's first element or null if no
element found. |
|
static
|
fromEnd(Iterable<T> iterable,
int n)
Returns the iterator's n:th item from the end of the iteration. |
|
static
|
fromEnd(Iterator<T> iterator,
int n)
Returns the iterator's n:th item from the end of the iteration. |
|
static
|
fromEndOrNull(Iterable<T> iterable,
int countFromEnd)
Returns the iterator's n:th item from the end of the iteration. |
|
static
|
fromEndOrNull(Iterator<T> iterator,
int n)
Returns the iterator's n:th item from the end of the iteration. |
|
static
|
last(Iterable<T> iterable)
Returns the given iterable's last element. |
|
static
|
last(Iterator<T> iterator)
Returns the given iterator's last element. |
|
static
|
lastOrNull(Iterable<T> iterable)
Returns the given iterable's last element or null if no
element found. |
|
static
|
lastOrNull(Iterator<T> iterator)
Returns the given iterator's last element or null if no
element found. |
|
static
|
single(Iterable<T> iterable)
Returns the given iterable's single element. |
|
static
|
single(Iterator<T> iterator)
Returns the given iterator's single element. |
|
static
|
singleOrNull(Iterable<T> iterable)
Returns the given iterable's single element or null if no
element found. |
|
static
|
singleOrNull(Iterator<T> iterator)
Returns the given iterator's single element or null if no
element found. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IteratorUtil()
Method Detail |
---|
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
.
{@link
- 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
.
{@link
- 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.
{@link
- 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
.
{@link
- 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 <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
.
{@link
- 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
.
{@link
- 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.
{@link
- 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
.
{@link
- NoSuchElementException} if there isn't exactly one
element.public static <T> T fromEndOrNull(Iterable<T> iterable, int countFromEnd)
null
is returned.
T
- the type of elements in iterator
.iterable
- the Iterable
to get elements from.countFromEnd
- the n:th item from the end to get.
null
if the iterator doesn't contain that many items.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<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> Iterable<T> asIterable(Iterator<T> iterator)
iterator
as an Iterable
. 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 mostly exists to make it easy to use an
Iterator
in a for-loop.
T
- the type of items in the iterator.iterator
- the iterator to expose as an Iterable
.
Iterable
.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 ClosableIterable<String> asIterable(File file)
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) 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.
Iterator
for iterating over the lines of a text file.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |