public class Iterators extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Iterators.Buffered<E>
An
Iterators.Buffered uses a single method to return
objects, buffering the result and returning it as the next element
if it is non-null. |
static class |
Iterators.Filter<E>
An
Iterators.Filter filters the stream of objects
returned by another iterator by subjecting them to an acceptance
test. |
static class |
Iterators.Modifier<E>
An
Iterator.Modifier uses a single abstract method
to operate on the elements returned by an underlying iterator
to return modified objects. |
static class |
Iterators.PrimitiveInt
A
Iterators.PrimitiveInt is an integer iterator that
also allows objects to be accessed as primitive int
values. |
| Modifier and Type | Method and Description |
|---|---|
static <E> Iterator<E> |
array(E[] members)
Returns an iterator over the specified array of objects.
|
static <E> Iterator<E> |
arraySlice(E[] members,
int start,
int length)
Returns a newly constructed iterator over the specified
object array slice.
|
static <E> Iterator<E> |
empty()
Returns an iterator that has no elements.
|
static Iterators.PrimitiveInt |
intArray(int[] members)
Returns an iterator over the array of primitive integers
specified.
|
static Iterators.PrimitiveInt |
intRange(int end)
Construct an Integer iterator from 0 (inclusive) the specified
end point (exclusive).
|
static Iterators.PrimitiveInt |
intRange(int start,
int end)
Returns a newly constructed primitive integer iterator that
iterates from the start (inclusive) to end (exclusive).
|
static <E> Iterator<E> |
list(E... es)
Returns an iterator constructed from the specified variable
length argument list of objects.
|
static <E> Iterator<E> |
pair(E e1,
E e2)
Returns a newly constructed iterator over the specified pair of
elements.
|
static <E> Iterator<E> |
sequence(Iterator<? extends E> it1,
Iterator<? extends E> it2)
Returns an iterator that runs through the first iterator's
elements and then runs through the second iterator's elements.
|
static <E> Iterator<E> |
sequence(Iterator<? extends Iterator<? extends E>> iteratorOfIterators) |
static <E> Iterator<E> |
sequence(List<? extends Iterator<? extends E>> iterators) |
static <E> Iterator<E> |
singleton(E e)
Returns an iterator over the single specified element.
|
static <E> Iterator<E> |
unmodifiable(Iterator<E> it)
Returns an unmodifiable view of the specified iterator.
|
public static <E> Iterator<E> empty()
hasNext() will always return false and next()
will always throw a NoSuchElementException.public static <E> Iterator<E> singleton(E e)
next() will return the specified element
on the first call, with subsequent calls
throwing a NoSuchElementException .e - The object to return in the iterator.public static <E> Iterator<E> pair(E e1, E e2)
Implementation Note: References to the elemenets are
removed from iterator after they are returned through next().
e1 - First element returned.e2 - Second element returned.public static <E> Iterator<E> list(E... es)
Remove is supported, but has no effect on anything as the list from which elements are being deleted is only used for the iterator.
es - Array of objects for iteration.public static <E> Iterator<E> unmodifiable(Iterator<E> it)
next() and hasNext() are delegated
to the specified iterator as made. Calls to remove()
throw unsupported operation exceptions.it - Iterator to view.public static <E> Iterator<E> sequence(Iterator<? extends E> it1, Iterator<? extends E> it2)
References to the iterators are freed after it is finished iterating.
it1 - The first iterator in the sequence.it2 - The second iterator in the sequence.public static <E> Iterator<E> sequence(Iterator<? extends Iterator<? extends E>> iteratorOfIterators)
public static <E> Iterator<E> array(E[] members)
Warning: The array is not copied, so any changes in the underlying array are reflected in the iterator.
Implementation Note: this class does not
automatically free references in the underlying array, because
the array may be used elswhere. If reference freeing is
critical here, a call to remove() after ever call to
next() will free the references in the array.
members - Array of elements over which to iterate.public static <E> Iterator<E> arraySlice(E[] members, int start, int length)
The remove() method is not supported.
Warning: The array is not copied, so any changes in the underlying array are reflected in the iterator.
Implementation Note: this class does not automatically free references in the underlying array, because the array may be used elswhere.
members - Array of objects over which to iterate.start - Index of first object to return.length - Number of objects to iterate.Illegal - argument exception if start < 0 or
start + length > objects.length().public static Iterators.PrimitiveInt intRange(int end)
remove().end - One plus the last integer returned.public static Iterators.PrimitiveInt intRange(int start, int end)
The returned iterator does not support remove().
start - The first and lowest value to return.end - One plus the last integer returned.IllegalArgumentException - If start > end.public static Iterators.PrimitiveInt intArray(int[] members)
There are no order restrictions on the array -- its elements may be in any order and may contain duplicates.
The returned iterator does not support remove().
members - Array of members to iterate.Copyright © 2016 Alias-i, Inc.. All rights reserved.