Class LongIterators
- java.lang.Object
-
- it.unimi.dsi.fastutil.longs.LongIterators
-
public final class LongIterators extends java.lang.Object
A class providing static methods and objects that do useful things with type-specific iterators.- See Also:
Iterator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LongIterators.EmptyIterator
A class returning no elements and a type-specific iterator interface.static class
LongIterators.UnmodifiableBidirectionalIterator
An unmodifiable wrapper class for bidirectional iterators.static class
LongIterators.UnmodifiableIterator
An unmodifiable wrapper class for iterators.static class
LongIterators.UnmodifiableListIterator
An unmodifiable wrapper class for list iterators.
-
Field Summary
Fields Modifier and Type Field Description static LongIterators.EmptyIterator
EMPTY_ITERATOR
An empty iterator.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
all(LongIterator iterator, java.util.function.LongPredicate predicate)
static boolean
any(LongIterator iterator, java.util.function.LongPredicate predicate)
static LongIterator
asLongIterator(java.util.Iterator i)
Wraps a standard iterator into a type-specific iterator.static LongListIterator
asLongIterator(java.util.ListIterator i)
Wraps a standard list iterator into a type-specific list iterator.static LongIterator
concat(LongIterator[] a)
Concatenates all iterators contained in an array.static LongIterator
concat(LongIterator[] a, int offset, int length)
Concatenates a sequence of iterators contained in an array.static LongBidirectionalIterator
fromTo(long from, long to)
Creates a type-specific bidirectional iterator over an interval.static int
indexOf(LongIterator iterator, java.util.function.LongPredicate predicate)
static LongList
pour(LongIterator i)
Pours an iterator, returning a type-specific list.static LongList
pour(LongIterator i, int max)
Pours an iterator, returning a type-specific list, with a limit on the number of elements.static int
pour(LongIterator i, LongCollection s)
Pours an iterator into a type-specific collection.static int
pour(LongIterator i, LongCollection s, int max)
Pours an iterator into a type-specific collection, with a limit on the number of elements.static LongListIterator
singleton(long element)
Returns an immutable iterator that iterates just over the given element.static LongBidirectionalIterator
unmodifiable(LongBidirectionalIterator i)
Returns an unmodifiable bidirectional iterator backed by the specified bidirectional iterator.static LongIterator
unmodifiable(LongIterator i)
Returns an unmodifiable iterator backed by the specified iterator.static LongListIterator
unmodifiable(LongListIterator i)
Returns an unmodifiable list iterator backed by the specified list iterator.static long[]
unwrap(LongIterator i)
Unwraps an iterator, returning an array.static long[]
unwrap(LongIterator i, int max)
Unwraps an iterator, returning an array, with a limit on the number of elements.static int
unwrap(LongIterator i, long[] array)
Unwraps an iterator into an array.static long
unwrap(LongIterator i, long[][] array)
Unwraps an iterator into a big array.static long
unwrap(LongIterator i, long[][] 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(LongIterator i, long[] 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(LongIterator i, LongCollection c)
Unwraps an iterator into a type-specific collection.static int
unwrap(LongIterator i, LongCollection c, int max)
Unwraps an iterator into a type-specific collection, with a limit on the number of elements.static long[][]
unwrapBig(LongIterator i)
Unwraps an iterator, returning a big array.static long[][]
unwrapBig(LongIterator i, long max)
Unwraps an iterator, returning a big array, with a limit on the number of elements.static LongListIterator
wrap(long[] array)
Wraps the given array into a type-specific list iterator.static LongListIterator
wrap(long[] array, int offset, int length)
Wraps the given part of an array into a type-specific list iterator.static LongIterator
wrap(ByteIterator iterator)
Returns an iterator backed by the specified byte iterator.static LongIterator
wrap(IntIterator iterator)
Returns an iterator backed by the specified integer iterator.static LongIterator
wrap(ShortIterator iterator)
Returns an iterator backed by the specified short iterator.
-
-
-
Field Detail
-
EMPTY_ITERATOR
public static final LongIterators.EmptyIterator EMPTY_ITERATOR
An empty iterator. It is serializable and cloneable.The class of this objects represent an abstract empty iterator that can iterate as a type-specific (list) iterator.
-
-
Method Detail
-
singleton
public static LongListIterator singleton(long element)
Returns an immutable iterator that iterates just over the given element.- Parameters:
element
- the only element to be returned by a type-specific list iterator.- Returns:
- an immutable iterator that iterates just over
element
.
-
wrap
public static LongListIterator wrap(long[] array, int offset, int length)
Wraps the given part of an array into a type-specific list iterator.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 indexoffset
.- Parameters:
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.- Returns:
- an iterator that will return
length
elements ofarray
starting at positionoffset
.
-
wrap
public static LongListIterator wrap(long[] array)
Wraps the given array into a type-specific list iterator.The type-specific list iterator returned by this method will return all elements of the given array.
- Parameters:
array
- an array to wrap into a type-specific list iterator.- Returns:
- an iterator that will the elements of
array
.
-
unwrap
public static int unwrap(LongIterator i, long[] array, int offset, int max)
Unwraps an iterator into an array starting at a given offset for a given number of elements.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 atoffset
. The number of actually unwrapped elements is returned (it may be less thanmax
if the iterator emits less thanmax
elements).- Parameters:
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.- Returns:
- the number of elements unwrapped.
-
unwrap
public static int unwrap(LongIterator i, long[] array)
Unwraps an iterator into an 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.
- Parameters:
i
- a type-specific iterator.array
- an array to contain the output of the iterator.- Returns:
- the number of elements unwrapped.
-
unwrap
public static long[] unwrap(LongIterator i, int max)
Unwraps an iterator, returning an array, with a limit on the number of elements.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.- Parameters:
i
- a type-specific iterator.max
- the maximum number of elements to be unwrapped.- Returns:
- an array containing the elements returned by the iterator (at most
max
).
-
unwrap
public static long[] unwrap(LongIterator i)
Unwraps an iterator, returning an array.This method iterates over the given type-specific iterator and returns an array containing the elements returned by the iterator.
- Parameters:
i
- a type-specific iterator.- Returns:
- an array containing the elements returned by the iterator.
-
unwrap
public static long unwrap(LongIterator i, long[][] array, long offset, long max)
Unwraps an iterator into a big array starting at a given offset for a given number of elements.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 atoffset
. The number of actually unwrapped elements is returned (it may be less thanmax
if the iterator emits less thanmax
elements).- Parameters:
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.- Returns:
- the number of elements unwrapped.
-
unwrap
public static long unwrap(LongIterator i, long[][] array)
Unwraps an iterator into a big 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.
- Parameters:
i
- a type-specific iterator.array
- a big array to contain the output of the iterator.- Returns:
- the number of elements unwrapped.
-
unwrap
public static int unwrap(LongIterator i, LongCollection c, int max)
Unwraps an iterator into a type-specific collection, with a limit on the number of elements.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 thanmax
if the iterator emits less thanmax
elements).- Parameters:
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.- Returns:
- the number of elements unwrapped. Note that this is the number of elements returned by the iterator, which is not necessarily the number of elements that have been added to the collection (because of duplicates).
-
unwrapBig
public static long[][] unwrapBig(LongIterator i, long max)
Unwraps an iterator, returning a big array, with a limit on the number of elements.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.- Parameters:
i
- a type-specific iterator.max
- the maximum number of elements to be unwrapped.- Returns:
- a big array containing the elements returned by the iterator (at most
max
).
-
unwrapBig
public static long[][] unwrapBig(LongIterator i)
Unwraps an iterator, returning a big array.This method iterates over the given type-specific iterator and returns a big array containing the elements returned by the iterator.
- Parameters:
i
- a type-specific iterator.- Returns:
- a big array containing the elements returned by the iterator.
-
unwrap
public static long unwrap(LongIterator i, LongCollection c)
Unwraps an iterator into a type-specific collection.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.
- Parameters:
i
- a type-specific iterator.c
- a type-specific collection to contain the output of the iterator.- Returns:
- the number of elements unwrapped. Note that this is the number of elements returned by the iterator, which is not necessarily the number of elements that have been added to the collection (because of duplicates).
-
pour
public static int pour(LongIterator i, LongCollection s, int max)
Pours an iterator into a type-specific collection, with a limit on the number of elements.This method iterates over the given type-specific iterator and adds the returned elements to the given collection (up to
max
).- Parameters:
i
- a type-specific iterator.s
- a type-specific collection.max
- the maximum number of elements to be poured.- Returns:
- the number of elements poured. Note that this is the number of elements returned by the iterator, which is not necessarily the number of elements that have been added to the collection (because of duplicates).
-
pour
public static int pour(LongIterator i, LongCollection s)
Pours an iterator into a type-specific collection.This method iterates over the given type-specific iterator and adds the returned elements to the given collection.
- Parameters:
i
- a type-specific iterator.s
- a type-specific collection.- Returns:
- the number of elements poured. Note that this is the number of elements returned by the iterator, which is not necessarily the number of elements that have been added to the collection (because of duplicates).
-
pour
public static LongList pour(LongIterator i, int max)
Pours an iterator, returning a type-specific list, with a limit on the number of elements.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.- Parameters:
i
- a type-specific iterator.max
- the maximum number of elements to be poured.- Returns:
- a type-specific list containing the returned elements, up to
max
.
-
pour
public static LongList pour(LongIterator i)
Pours an iterator, returning a type-specific list.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.
- Parameters:
i
- a type-specific iterator.- Returns:
- a type-specific list containing the returned elements.
-
asLongIterator
public static LongIterator asLongIterator(java.util.Iterator i)
Wraps a standard iterator into a type-specific iterator.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 byi
: 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.- Parameters:
i
- an iterator.- Returns:
- a type-specific iterator backed by
i
.
-
asLongIterator
public static LongListIterator asLongIterator(java.util.ListIterator i)
Wraps a standard list iterator into a type-specific list iterator.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 byi
: 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.- Parameters:
i
- a list iterator.- Returns:
- a type-specific list iterator backed by
i
.
-
any
public static boolean any(LongIterator iterator, java.util.function.LongPredicate predicate)
-
all
public static boolean all(LongIterator iterator, java.util.function.LongPredicate predicate)
-
indexOf
public static int indexOf(LongIterator iterator, java.util.function.LongPredicate predicate)
-
fromTo
public static LongBidirectionalIterator fromTo(long from, long to)
Creates a type-specific bidirectional iterator over an interval.The type-specific bidirectional iterator returned by this method will return the elements
from
,from+1
,…,to-1
.Note that all other type-specific interval iterator are list iterators. Of course, this is not possible with longs as the index returned by
nextIndex()
/previousIndex()
would exceed an integer.- Parameters:
from
- the starting element (inclusive).to
- the ending element (exclusive).- Returns:
- a type-specific bidirectional iterator enumerating the elements from
from
toto
.
-
concat
public static LongIterator concat(LongIterator[] a)
Concatenates all iterators contained in an array.This method returns an iterator that will enumerate in order the elements returned by all iterators contained in the given array.
- Parameters:
a
- an array of iterators.- Returns:
- an iterator obtained by concatenation.
-
concat
public static LongIterator concat(LongIterator[] a, int offset, int length)
Concatenates a sequence of iterators contained in an array.This method returns an iterator that will enumerate in order the elements returned by
a[offset]
, then those returned bya[offset + 1]
, and so on up toa[offset + length - 1]
.- Parameters:
a
- an array of iterators.offset
- the index of the first iterator to concatenate.length
- the number of iterators to concatenate.- Returns:
- an iterator obtained by concatenation of
length
elements ofa
starting atoffset
.
-
unmodifiable
public static LongIterator unmodifiable(LongIterator i)
Returns an unmodifiable iterator backed by the specified iterator.- Parameters:
i
- the iterator to be wrapped in an unmodifiable iterator.- Returns:
- an unmodifiable view of the specified iterator.
-
unmodifiable
public static LongBidirectionalIterator unmodifiable(LongBidirectionalIterator i)
Returns an unmodifiable bidirectional iterator backed by the specified bidirectional iterator.- Parameters:
i
- the bidirectional iterator to be wrapped in an unmodifiable bidirectional iterator.- Returns:
- an unmodifiable view of the specified bidirectional iterator.
-
unmodifiable
public static LongListIterator unmodifiable(LongListIterator i)
Returns an unmodifiable list iterator backed by the specified list iterator.- Parameters:
i
- the list iterator to be wrapped in an unmodifiable list iterator.- Returns:
- an unmodifiable view of the specified list iterator.
-
wrap
public static LongIterator wrap(ByteIterator iterator)
Returns an iterator backed by the specified byte iterator.- Parameters:
iterator
- a byte iterator.- Returns:
- an iterator backed by the specified byte iterator.
-
wrap
public static LongIterator wrap(ShortIterator iterator)
Returns an iterator backed by the specified short iterator.- Parameters:
iterator
- a short iterator.- Returns:
- an iterator backed by the specified short iterator.
-
wrap
public static LongIterator wrap(IntIterator iterator)
Returns an iterator backed by the specified integer iterator.- Parameters:
iterator
- an integer iterator.- Returns:
- an iterator backed by the specified integer iterator.
-
-