public final class ShortIterators
extends java.lang.Object
Iterator
Modifier and Type | Class and Description |
---|---|
static class |
ShortIterators.AbstractIndexBasedIterator
A skeletal implementation for an iterator backed by an index-based data store.
|
static class |
ShortIterators.AbstractIndexBasedListIterator
A skeletal implementation for a list-iterator backed by an index-based data store.
|
static class |
ShortIterators.EmptyIterator
A class returning no elements and a type-specific iterator interface.
|
static class |
ShortIterators.UnmodifiableBidirectionalIterator
An unmodifiable wrapper class for bidirectional iterators.
|
static class |
ShortIterators.UnmodifiableIterator
An unmodifiable wrapper class for iterators.
|
static class |
ShortIterators.UnmodifiableListIterator
An unmodifiable wrapper class for list iterators.
|
Modifier and Type | Field and Description |
---|---|
static ShortIterators.EmptyIterator |
EMPTY_ITERATOR
An empty iterator.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
all(ShortIterator iterator,
java.util.function.IntPredicate predicate)
Returns whether all elements returned by the given iterator satisfy the given predicate.
|
static boolean |
all(ShortIterator iterator,
ShortPredicate predicate)
Returns whether all elements returned by the given iterator satisfy the given predicate.
|
static boolean |
any(ShortIterator iterator,
java.util.function.IntPredicate predicate)
Returns whether an element returned by the given iterator satisfies the given predicate.
|
static boolean |
any(ShortIterator iterator,
ShortPredicate predicate)
Returns whether an element returned by the given iterator satisfies the given predicate.
|
static ShortIterator |
asShortIterator(java.util.Iterator i)
Wraps a standard iterator into a type-specific iterator.
|
static ShortListIterator |
asShortIterator(java.util.ListIterator i)
Wraps a standard list iterator into a type-specific list iterator.
|
static ShortIterator |
concat(ShortIterator... a)
Concatenates all iterators contained in an array.
|
static ShortIterator |
concat(ShortIterator[] a,
int offset,
int length)
Concatenates a sequence of iterators contained in an array.
|
static ShortListIterator |
fromTo(short from,
short to)
Creates a type-specific list iterator over an interval.
|
static int |
indexOf(ShortIterator iterator,
java.util.function.IntPredicate predicate)
Returns the index of the first element returned by the given iterator that satisfies the given predicate, or −1 if
no such element was found.
|
static int |
indexOf(ShortIterator iterator,
ShortPredicate predicate)
Returns the index of the first element returned by the given iterator that satisfies the given predicate, or −1 if
no such element was found.
|
static ShortIterator |
narrow(java.util.PrimitiveIterator.OfInt i)
Wrap a JDK primitive iterator to a type-specific iterator, making checked
narrowed casts.
|
static ShortList |
pour(ShortIterator i)
Pours an iterator, returning a type-specific list.
|
static ShortList |
pour(ShortIterator i,
int max)
Pours an iterator, returning a type-specific list, with a limit on the number of elements.
|
static int |
pour(ShortIterator i,
ShortCollection s)
Pours an iterator into a type-specific collection.
|
static int |
pour(ShortIterator i,
ShortCollection s,
int max)
Pours an iterator into a type-specific collection, with a limit on the number of elements.
|
static ShortListIterator |
singleton(short element)
Returns an immutable iterator that iterates just over the given element.
|
static ShortIterator |
uncheckedNarrow(java.util.PrimitiveIterator.OfInt i)
Wrap a JDK primitive iterator to a type-specific iterator, making unchecked
narrowing casts.
|
static ShortBidirectionalIterator |
unmodifiable(ShortBidirectionalIterator i)
Returns an unmodifiable bidirectional iterator backed by the specified bidirectional iterator.
|
static ShortIterator |
unmodifiable(ShortIterator i)
Returns an unmodifiable iterator backed by the specified iterator.
|
static ShortListIterator |
unmodifiable(ShortListIterator i)
Returns an unmodifiable list iterator backed by the specified list iterator.
|
static short[] |
unwrap(ShortIterator i)
Unwraps an iterator, returning an array.
|
static short[] |
unwrap(ShortIterator i,
int max)
Unwraps an iterator, returning an array, with a limit on the number of elements.
|
static int |
unwrap(ShortIterator i,
short[] array)
Unwraps an iterator into an array.
|
static long |
unwrap(ShortIterator i,
short[][] array)
Unwraps an iterator into a big array.
|
static long |
unwrap(ShortIterator i,
short[][] array,
long offset,
long max)
Unwraps an iterator into a big array starting at a given offset for a given number of elements.
|
static int |
unwrap(ShortIterator i,
short[] array,
int offset,
int max)
Unwraps an iterator into an array starting at a given offset for a given number of elements.
|
static long |
unwrap(ShortIterator i,
ShortCollection c)
Unwraps an iterator into a type-specific collection.
|
static int |
unwrap(ShortIterator i,
ShortCollection c,
int max)
Unwraps an iterator into a type-specific collection, with a limit on the number of elements.
|
static short[][] |
unwrapBig(ShortIterator i)
Unwraps an iterator, returning a big array.
|
static short[][] |
unwrapBig(ShortIterator i,
long max)
Unwraps an iterator, returning a big array, with a limit on the number of elements.
|
static IntIterator |
widen(ShortIterator i)
Wrap a type-specific iterator to a JDK compatible primitive iterator.
|
static ShortIterator |
wrap(ByteIterator iterator)
Returns an iterator backed by the specified byte iterator.
|
static ShortListIterator |
wrap(short[] array)
Wraps the given array into a type-specific list iterator.
|
static ShortListIterator |
wrap(short[] array,
int offset,
int length)
Wraps the given part of an array into a type-specific list iterator.
|
public static final ShortIterators.EmptyIterator EMPTY_ITERATOR
The class of this objects represent an abstract empty iterator that can iterate as a type-specific (list) iterator.
public static ShortListIterator singleton(short element)
element
- the only element to be returned by a type-specific list iterator.element
.public static ShortListIterator wrap(short[] array, int offset, int length)
The type-specific list iterator returned by this method will iterate
length
times, returning consecutive elements of the given
array starting from the one with index offset
.
array
- an array to wrap into a type-specific list iterator.offset
- the first element of the array to be returned.length
- the number of elements to return.length
elements of array
starting at position offset
.public static ShortListIterator wrap(short[] array)
The type-specific list iterator returned by this method will return all elements of the given array.
array
- an array to wrap into a type-specific list iterator.array
.public static int unwrap(ShortIterator i, short[] array, int offset, int max)
This method iterates over the given type-specific iterator and stores the elements
returned, up to a maximum of length
, in the given array starting at offset
.
The number of actually unwrapped elements is returned (it may be less than max
if
the iterator emits less than max
elements).
i
- a type-specific iterator.array
- an array to contain the output of the iterator.offset
- the first element of the array to be returned.max
- the maximum number of elements to unwrap.public static int unwrap(ShortIterator i, short[] array)
This method iterates over the given type-specific iterator and stores the elements returned in the given array. The iteration will stop when the iterator has no more elements or when the end of the array has been reached.
i
- a type-specific iterator.array
- an array to contain the output of the iterator.public static short[] unwrap(ShortIterator i, int max)
This method iterates over the given type-specific iterator and returns an array
containing the elements returned by the iterator. At most max
elements
will be returned.
i
- a type-specific iterator.max
- the maximum number of elements to be unwrapped.max
).public static short[] unwrap(ShortIterator i)
This method iterates over the given type-specific iterator and returns an array containing the elements returned by the iterator.
i
- a type-specific iterator.public static long unwrap(ShortIterator i, short[][] array, long offset, long max)
This method iterates over the given type-specific iterator and stores the elements
returned, up to a maximum of length
, in the given big array starting at offset
.
The number of actually unwrapped elements is returned (it may be less than max
if
the iterator emits less than max
elements).
i
- a type-specific iterator.array
- a big array to contain the output of the iterator.offset
- the first element of the array to be returned.max
- the maximum number of elements to unwrap.public static long unwrap(ShortIterator i, short[][] array)
This method iterates over the given type-specific iterator and stores the elements returned in the given big array. The iteration will stop when the iterator has no more elements or when the end of the array has been reached.
i
- a type-specific iterator.array
- a big array to contain the output of the iterator.public static int unwrap(ShortIterator i, ShortCollection c, int max)
This method iterates over the given type-specific iterator and stores the elements
returned, up to a maximum of max
, in the given type-specific collection.
The number of actually unwrapped elements is returned (it may be less than max
if
the iterator emits less than max
elements).
i
- a type-specific iterator.c
- a type-specific collection array to contain the output of the iterator.max
- the maximum number of elements to unwrap.public static short[][] unwrapBig(ShortIterator i, long max)
This method iterates over the given type-specific iterator and returns a big array
containing the elements returned by the iterator. At most max
elements
will be returned.
i
- a type-specific iterator.max
- the maximum number of elements to be unwrapped.max
).public static short[][] unwrapBig(ShortIterator i)
This method iterates over the given type-specific iterator and returns a big array containing the elements returned by the iterator.
i
- a type-specific iterator.public static long unwrap(ShortIterator i, ShortCollection c)
This method iterates over the given type-specific iterator and stores the elements returned in the given type-specific collection. The returned count on the number unwrapped elements is a long, so that it will work also with very large collections.
i
- a type-specific iterator.c
- a type-specific collection to contain the output of the iterator.public static int pour(ShortIterator i, ShortCollection s, int max)
This method iterates over the given type-specific iterator and adds
the returned elements to the given collection (up to max
).
i
- a type-specific iterator.s
- a type-specific collection.max
- the maximum number of elements to be poured.public static int pour(ShortIterator i, ShortCollection s)
This method iterates over the given type-specific iterator and adds the returned elements to the given collection.
i
- a type-specific iterator.s
- a type-specific collection.public static ShortList pour(ShortIterator i, int max)
This method iterates over the given type-specific iterator and returns
a type-specific list containing the returned elements (up to max
). Iteration
on the returned list is guaranteed to produce the elements in the same order
in which they appeared in the iterator.
i
- a type-specific iterator.max
- the maximum number of elements to be poured.max
.public static ShortList pour(ShortIterator i)
This method iterates over the given type-specific iterator and returns a list containing the returned elements. Iteration on the returned list is guaranteed to produce the elements in the same order in which they appeared in the iterator.
i
- a type-specific iterator.public static ShortIterator asShortIterator(java.util.Iterator i)
This method wraps a standard iterator into a type-specific one which will handle the
type conversions for you. Of course, any attempt to wrap an iterator returning the
instances of the wrong class will generate a ClassCastException
. The
returned iterator is backed by i
: changes to one of the iterators
will affect the other, too.
i
- an iterator.i
.i
is already type-specific, it will returned and no new object
will be generated.public static ShortIterator narrow(java.util.PrimitiveIterator.OfInt i)
i
- an iterator.i
.next
method throws IllegalArgumentException
if any element would underflow or overflow.public static ShortIterator uncheckedNarrow(java.util.PrimitiveIterator.OfInt i)
No test is done for overflow or underflow.
i
- an iterator.i
.public static IntIterator widen(ShortIterator i)
i
- an iteratori
public static ShortListIterator asShortIterator(java.util.ListIterator i)
This method wraps a standard list iterator into a type-specific one
which will handle the type conversions for you. Of course, any attempt
to wrap an iterator returning the instances of the wrong class will
generate a ClassCastException
. The
returned iterator is backed by i
: changes to one of the iterators
will affect the other, too.
If i
is already type-specific, it will returned and no new object
will be generated.
i
- a list iterator.i
.public static boolean any(ShortIterator iterator, ShortPredicate predicate)
Short circuit evaluation is performed; the first true
from the predicate terminates the loop.
iterator
satisfies predicate
.public static boolean any(ShortIterator iterator, java.util.function.IntPredicate predicate)
Short circuit evaluation is performed; the first true
from the predicate terminates the loop.
iterator
satisfies predicate
.
lambda to perform widening casts. Please use the type-specific overload to avoid this overhead.public static boolean all(ShortIterator iterator, ShortPredicate predicate)
Short circuit evaluation is performed; the first false
from the predicate terminates the loop.
iterator
satisfy predicate
.public static boolean all(ShortIterator iterator, java.util.function.IntPredicate predicate)
Short circuit evaluation is performed; the first false
from the predicate terminates the loop.
iterator
satisfy predicate
.public static int indexOf(ShortIterator iterator, ShortPredicate predicate)
The next element returned by the iterator always considered element 0, even for
ListIterators
. In other words ListIterator.nextIndex
is ignored.
iterator
that satisfies predicate
, or −1 if
no such element was found.public static int indexOf(ShortIterator iterator, java.util.function.IntPredicate predicate)
The next element returned by the iterator always considered element 0, even for
ListIterators
. In other words ListIterator.nextIndex
is ignored.
iterator
that satisfies predicate
, or −1 if
no such element was found.public static ShortListIterator fromTo(short from, short to)
The type-specific list iterator returned by this method will return the
elements from
, from+1
,…, to-1
.
from
- the starting element (inclusive).to
- the ending element (exclusive).from
to to
.public static ShortIterator concat(ShortIterator... a)
This method returns an iterator that will enumerate in order the elements returned by all iterators contained in the given array.
a
- an array of iterators.public static ShortIterator concat(ShortIterator[] a, int offset, int length)
This method returns an iterator that will enumerate in order the elements returned
by a[offset]
, then those returned
by a[offset + 1]
, and so on up to
a[offset + length - 1]
.
a
- an array of iterators.offset
- the index of the first iterator to concatenate.length
- the number of iterators to concatenate.length
elements of a
starting at offset
.public static ShortIterator unmodifiable(ShortIterator i)
i
- the iterator to be wrapped in an unmodifiable iterator.public static ShortBidirectionalIterator unmodifiable(ShortBidirectionalIterator i)
i
- the bidirectional iterator to be wrapped in an unmodifiable bidirectional iterator.public static ShortListIterator unmodifiable(ShortListIterator i)
i
- the list iterator to be wrapped in an unmodifiable list iterator.public static ShortIterator wrap(ByteIterator iterator)
iterator
- a byte iterator.