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
removeare passed through to the underlying iterator;addandsetare 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
funto the corresponding element ofelems - Throws:
NullPointerException- iffunorelemsis null
-
unmodifiableListIterator
Returns an unmodifiable view on a list iterator.Changes to the underlying iterator are reflected in the result.
The operations
remove,addandsetare not supported.- Type Parameters:
A- the element type- Parameters:
elems- some elements- Returns:
- a list iterator that has the same elements as
elemsbut allows no modification - Throws:
NullPointerException- ifelemsis 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
removeandsetare passed through to either of the underlying iterators;addis 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
i1followed by all elements ofi2 - Throws:
NullPointerException- ifi1ori2is 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
removeandsetare passed through to either of the underlying iterator;addis not supported.- Type Parameters:
A- the element type- Parameters:
i1- the first list iteratori2- the second list iteratorfirst-trueif the resulting list iterator should start at the position ofl1,falseif it should start atl2- Returns:
- a list iterator that traverses all elements of
i1followed by all elements ofi2 - Throws:
NullPointerException- ifi1ori2is 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,addandsetare 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::sizewill 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- ifiorsizeis 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
nextandprevious. Whether there are adjacent elements according tohasPreviousandhasNextis determined byfirst; aNoSuchElementExceptionmay be thrown ifsecondhas fewer elements on either side.Changes to the underlying iterators are reflected in the result.
Calls to
removeare passed through to the underlying iterator;addandsetare 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
funto the corresponding elements offirstandsecond - Throws:
NullPointerException- iffun,firstorsecondis null
-