Package ste.lloop
Class Loop
java.lang.Object
ste.lloop.Loop
Provides a fluent API for creating loops.
This class is the main entry point for creating loops. Use one of the static on methods
to start building a loop.
Example usage:
// Numeric loop from 0 to 10 (inclusive)
Loop.on().from(0).to(10).loop(i -> {
// do something with i
});
// Loop over an array of strings
Loop.on("a", "b", "c").loop(element -> {
// do something with element
});
// Loop over an array of strings, from index 1 up to (and including) index 3
Loop.on(new String[]{"a", "b", "c", "d"}).from(1).to(3).loop((index, element) -> {
// do something with index and element
});
// Numeric loop from 0 to 10, with a step of 2
Loop.on().from(0).to(10).step(2).loop(i -> {
// i will be 0, 2, 4, 6, 8, 10
});
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidSame as brk() - which version do you prefer? please let me know, we will remove the less voted one.static voidThrows aReturnValueexception with the given value.static NumericSequenceon()Creates a new numeric loop.static <T> ForwardOnlySequence<T> Creates a new loop over the given iterable.static <T> ListSequence<T> Creates a new loop over the given list.static <T> ArraySequence<T> on(T... items) Creates a new loop over the given items.
-
Method Details
-
on
Creates a new numeric loop.- Returns:
- a new
NumericSequenceinstance
-
on
Creates a new loop over the given items. This method supports both varargs and passing an array directly.- Type Parameters:
T- the type of the items- Parameters:
items- the items to loop over (can be varargs or an array)- Returns:
- a new
ArraySequenceinstance
-
on
Creates a new loop over the given list.- Type Parameters:
T- the type of the items in the list- Parameters:
list- the list to loop over- Returns:
- a new
ListSequenceinstance
-
on
Creates a new loop over the given iterable.- Type Parameters:
T- the type of the items in the iterable- Parameters:
iterable- the iterable to loop over- Returns:
- a new
ForwardOnlySequenceinstance
-
brk
Throws aReturnValueexception with the given value. This method is intended to be used inside a loop to break out of it and return a value.- Parameters:
value- the value to return- Throws:
ReturnValue- with the given value
-
_break_
Same as brk() - which version do you prefer? please let me know, we will remove the less voted one.- Parameters:
value- the value to return- Throws:
ReturnValue- with the given value
-