public class Loop<T> extends BasicLoop<Loop.Item<T>>
This is useful in cases when the loop is manipulated from the outside.
It is also restricted to non-null
values.
As the underlying BasicLoop
this class is not thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
Loop.Item<T>
Generic loop item.
|
Countable.Base<TT>
Constructor and Description |
---|
Loop()
Empty loop constructor.
|
Loop(java.lang.Iterable<T> elements)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Loop.Item<T> |
add(T value)
Add a value to the end of the loop.
|
void |
addAll(java.lang.Iterable<? extends T> values)
Add all values.
|
Countable<T> |
closedValueView()
View this loop's values as a countable which is "closed".
|
Loop.Item<T> |
findFirstValue(java.util.function.Predicate<? super T> condition)
Find the first item in this loop for which the value fulfills a given condition.
|
Loop.Item<T> |
findLastValue(java.util.function.Predicate<? super T> condition)
Find the last item in this loop for which the value fulfills a given condition.
|
T |
firstValue()
Get the value of the first item in this loop.
|
void |
forEachValue(java.util.function.Consumer<? super T> valueAction)
Perform an action for each value in this loop.
|
T |
lastValue()
Get the value of the last item in this loop.
|
boolean |
rotateBackwardUntilValue(java.util.function.Predicate<? super T> condition)
Rotate this loop backward until the value of the first item fulfills a given condition.
|
boolean |
rotateForwardUntilValue(java.util.function.Predicate<? super T> condition)
Rotate this loop forward until the value of the first item fulfills a given condition.
|
Countable<T> |
values()
Get a countable view of the values of this loop.
|
add, addAll, clear, closedItemView, findFirst, findLast, getFirstItem, getFirstItemOrNull, getLastItem, getLastItemOrNull, isEmpty, iterator, removeSuccessiveDuplicates, removeSuccessiveDuplicates, rotate, rotateBackwardUntil, rotateForwardUntil, size, toMultiLineString, toString, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAllTo, addToArray, asBase, asCollection, combined, combined, containsEq, containsRef, downCast, empty, equal, equals, filtered, filteredToIndexable, filterToCountable, first, foldLeft, forEachFragile, fromOptional, frozen, frozen, groupingBy, groupingBy, hasAll, hasAny, isSorted, isStrictlySorted, last, mappingBy, mappingBy, optional, orderedCombination, singleton, sorted, toArray, toArray, toList, toString, uniform, view, viewArray, viewArray, viewCollection, viewCollection, viewCollectionN, viewCollectionN
@NotNull public final Countable<T> values()
closedValueView()
@NotNull public Countable<T> closedValueView()
values()
@NotNull public Loop.Item<T> add(@NotNull T value)
value
- value to addpublic void addAll(@NotNull java.lang.Iterable<? extends T> values)
values
- values to add to this looppublic T firstValue()
java.util.NoSuchElementException
- if this countable is emptypublic T lastValue()
java.util.NoSuchElementException
- if this countable is empty@Nullable public Loop.Item<T> findFirstValue(@NotNull java.util.function.Predicate<? super T> condition)
condition
- value conditionnull
if none matches@Nullable public Loop.Item<T> findLastValue(@NotNull java.util.function.Predicate<? super T> condition)
condition
- value conditionnull
if none matchespublic boolean rotateForwardUntilValue(@NotNull java.util.function.Predicate<? super T> condition)
condition
- value conditiontrue
if the condition is now fulfilled for the first
value,
false
if not or if this loop is emptypublic boolean rotateBackwardUntilValue(@NotNull java.util.function.Predicate<? super T> condition)
condition
- value conditiontrue
if the condition is now fulfilled for the first
value,
false
if not or if this loop is empty