Class ListIterators
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A> ListIterator
<A> concat
(ListIterator<A> i1, ListIterator<A> i2) Returns a view on a list iterator that has all elements of two list iterators one after the other.static <A> ListIterator
<A> concat
(ListIterator<A> i1, ListIterator<A> i2, boolean first) Returns a view on a list iterator that has all elements of two list iterators one after the other.static <A,
B> ListIterator <B> map
(Function<? super A, ? extends B> fun, ListIterator<? extends A> elems) Returns a view on a list iterator that has all elements transformed by a given function.static <A> ListIterator
<A> reverse
(ListIterator<A> i, IntSupplier size) Returns a view on a list iterator that has all elements in reverse order.static <A> ListIterator
<A> unmodifiableListIterator
(ListIterator<? extends A> elems) Returns an unmodifiable view on a list iterator.static <A,
B, C> ListIterator <C> zip
(BiFunction<? super A, ? super B, ? extends C> fun, ListIterator<? extends A> left, ListIterator<? extends B> right) Returns a view on two list iterators that has elements combined pairwise by a given function.
-
Method Details
-
map
public static <A,B> ListIterator<B> map(Function<? super A, ? extends B> fun, ListIterator<? extends A> elems) Returns a view on a list iterator that has all elements transformed by a given function.Changes to the underlying iterator are reflected in the result.
Calls to
remove
are passed through to the underlying iterator;add
andset
are not supported.- Type Parameters:
A
- the source element typeB
- the target element type- Parameters:
fun
- a transformer functionelems
- some elements- Returns:
- a list iterator where each element is computed on the fly by applying
fun
to the corresponding element ofelems
- Throws:
NullPointerException
- iffun
orelems
is null
-
unmodifiableListIterator
Returns an unmodifiable view on a list iterator.Changes to the underlying iterator are reflected in the result.
The operations
remove
,add
andset
are not supported.- Type Parameters:
A
- the element type- Parameters:
elems
- some elements- Returns:
- a list iterator that has the same elements as
elems
but allows no modification - Throws:
NullPointerException
- ifelems
is null
-
concat
Returns a view on a list iterator that has all elements of two list iterators one after the other.The concatenated list iterator starts at the position of the first given list iterator. The second list iterator is rewound to index zero before this method returns.
Changes to the underlying iterators are reflected in the result.
Calls to
remove
andset
are passed through to either of the underlying iterators;add
is not supported.- Type Parameters:
A
- the element type- Parameters:
i1
- the first list iteratori2
- the second list iterator- Returns:
- a list iterator that traverses all elements of
i1
followed by all elements ofi2
- Throws:
NullPointerException
- ifi1
ori2
is null
-
concat
Returns a view on a list iterator that has all elements of two list iterators one after the other.The concatenated list iterator starts at the position of one of the given list iterators, at the caller's choice. The other list iterator is wound to the appropriate extremal position (the first to maximal index, the second to zero) before this method returns.
Changes to the underlying iterators are reflected in the result.
Calls to
remove
andset
are passed through to either of the underlying iterator;add
is not supported.- Type Parameters:
A
- the element type- Parameters:
i1
- the first list iteratori2
- the second list iteratorfirst
-true
if the resulting list iterator should start at the position ofl1
,false
if it should start atl2
- Returns:
- a list iterator that traverses all elements of
i1
followed by all elements ofi2
- Throws:
NullPointerException
- ifi1
ori2
is null
-
reverse
Returns a view on a list iterator that has all elements in reverse order.Changes to the underlying iterator are reflected in the result.
Calls to
remove
,add
andset
are passed through to the underlying iterator.Dynamic tracking of index positions requires a callback that can determine the current size of the underlying list. Often a method reference
mylist::size
will do.- Type Parameters:
A
- the element type- Parameters:
i
- a list iteratorsize
- a callback that returns the current length of the underlying list- Returns:
- a list iterator where the elements are backwards with respect to
i
- Throws:
NullPointerException
- ifi
orsize
is null
-
zip
public static <A,B, ListIterator<C> zipC> (BiFunction<? super A, ? super B, ? extends C> fun, ListIterator<? extends A> left, ListIterator<? extends B> right) Returns a view on two list iterators that has elements combined pairwise by a given function.The two underlying iterators are moved in lockstep by
next
andprevious
. Whether there are adjacent elements according tohasPrevious
andhasNext
is determined byfirst
; aNoSuchElementException
may be thrown ifsecond
has fewer elements on either side.Changes to the underlying iterators are reflected in the result.
Calls to
remove
are passed through to the underlying iterator;add
andset
are not supported.- Type Parameters:
A
- the first source element typeB
- the second source element typeC
- the target element type- Parameters:
fun
- a combiner functionleft
- the first list iteratorright
- the second list iterator- Returns:
- a list iterator where each element is computed on the fly by
applying
fun
to the corresponding elements offirst
andsecond
- Throws:
NullPointerException
- iffun
,first
orsecond
is null
-