public class FunctionalIterate extends Object
Modifier and Type | Method and Description |
---|---|
static <K,V,E extends Exception> |
iterateMap(Map<K,V> map,
CheckedBiConsumer<K,V,E> consumer)
Iterate through all entries in a
Map . |
static <E extends Exception> |
repeat(int numberTimes,
CheckedRunnable<E> operation)
Repeats an operation a number of times.
|
static <T,E extends Exception> |
repeatAsStream(int numberTimes,
Class<? extends E> throwableClass,
CheckedSupplier<T,E> supplier)
Repeats an operation a number of times, to form a
Stream . |
static <E extends Exception> |
repeatCountSuccessful(int numberTimes,
CheckedBooleanSupplier<E> operation)
Repeats an operation a number of times, counting the number of times the operation returns
true.
|
static <E extends Exception> |
repeatUntil(int maxNumberTimes,
CheckedBooleanSupplier<E> supplier)
Repeats an operation until a true value is returned.
|
static <E extends Exception> |
repeatWithIndex(int numberTimes,
CheckedIntConsumer<E> operation)
Repeats an operation a number of times, passing an increment index to
operation each
time. |
static <T,E extends Exception> |
reverseIterateArray(T[] array,
CheckedConsumer<T,E> consumer)
Iterates through every element in an array in reverse order
|
public static <E extends Exception> void repeat(int numberTimes, CheckedRunnable<E> operation) throws E extends Exception
E
- an exception that may be thrown by operation
.numberTimes
- how many times to repeat the operationoperation
- the operationE
- if operation
throws it.E extends Exception
public static <E extends Exception> int repeatCountSuccessful(int numberTimes, CheckedBooleanSupplier<E> operation) throws E extends Exception
E
- an exception that may be thrown by operation
.numberTimes
- how many times to repeat the operationoperation
- the operation, which returns true for success, or false for failure.numberTimes
).E
- if operation
throws it.E extends Exception
public static <E extends Exception> void repeatWithIndex(int numberTimes, CheckedIntConsumer<E> operation) throws E extends Exception
operation
each
time.
The index begins at 0 and will increment to numberTimes -1
(inclusive).
E
- an exception that may be thrown by operation
.numberTimes
- how many times to repeat the operationoperation
- the operation to execute given an indexE
- if operation
throws it.E extends Exception
public static <E extends Exception> boolean repeatUntil(int maxNumberTimes, CheckedBooleanSupplier<E> supplier) throws E extends Exception
E
- an exception that may be thrown by the suppliermaxNumberTimes
- the maximum number of times to repeat if no true value is returned.supplier
- the operation to repeat that returns true or falseE
- if supplier
throws an exception.E extends Exception
public static <T,E extends Exception> java.util.stream.Stream<T> repeatAsStream(int numberTimes, Class<? extends E> throwableClass, CheckedSupplier<T,E> supplier) throws E extends Exception
Stream
.T
- type of element to created in the Stream
.E
- an exception that may be thrown by operation
.numberTimes
- how many times to repeat the operationthrowableClass
- the class of E
.supplier
- the operationStream
of numberTimes
* the objects created by supplier
.E
- if operation
throws it.E extends Exception
public static <K,V,E extends Exception> void iterateMap(Map<K,V> map, CheckedBiConsumer<K,V,E> consumer) throws E extends Exception
Map
.K
- map key type, see corresponding parameter in @{link Map}.V
- map value type, see corresponding parameter in @{link Map}.E
- an exception that may be thrown by consumer
.map
- the map whose entries will be iterated.consumer
- called for each entry.E
- if throw by consumer
.E extends Exception
public static <T,E extends Exception> void reverseIterateArray(T[] array, CheckedConsumer<T,E> consumer) throws E extends Exception
T
- array element typeE
- an exception that may be thrown by consumer
.array
- the arrayconsumer
- called for each element in the array.E
- if throw by consumer
.E extends Exception
Copyright © 2010–2023 Owen Feehan, ETH Zurich, University of Zurich, Hoffmann-La Roche. All rights reserved.