Package org.kiwiproject.collect
Class KiwiIterators
- java.lang.Object
-
- org.kiwiproject.collect.KiwiIterators
-
-
Constructor Summary
Constructors Constructor Description KiwiIterators()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Iterator<T>
cycleForever(Iterable<T> iterable)
Returns a thread-safe iterator that cycles indefinitely over the elements ofiterable
, base on Guava'sIterables.cycle(Iterable)
.static <T> Iterator<T>
cycleForever(T... elements)
Returns a thread-safe iterator that cycles indefinitely over the elements ofiterable
, base on Guava'sIterables.cycle(Iterable)
.
-
-
-
Method Detail
-
cycleForever
public static <T> Iterator<T> cycleForever(Iterable<T> iterable)
Returns a thread-safe iterator that cycles indefinitely over the elements ofiterable
, base on Guava'sIterables.cycle(Iterable)
. The differences from Guava is that the returned iterator provides thread-safety; makes an immutable copy of the provided iterable; and does not support element removal regardless of whether the original iterable does.Typical use cases include round-robin scenarios, such as round-robin between replicated service registries like Netflix Eureka.
The returned iterator does not support
Iterator.remove()
nor does it supportIterator.forEachRemaining(Consumer)
, as the entire point is to cycle forever.- Type Parameters:
T
- the type of objects in the Iterable- Parameters:
iterable
- the Iterable to cycle- Returns:
- an Iterator that cycles through the given Iterable without terminating
-
cycleForever
@SafeVarargs public static <T> Iterator<T> cycleForever(T... elements)
Returns a thread-safe iterator that cycles indefinitely over the elements ofiterable
, base on Guava'sIterables.cycle(Iterable)
. The differences from Guava is that the returned iterator provides thread-safety; makes an immutable copy of the provided iterable; and does not support element removal regardless of whether the original iterable does.Typical use cases include round-robin scenarios, such as round-robin between replicated service registries like Netflix Eureka.
The returned iterator does not support
Iterator.remove()
nor does it supportIterator.forEachRemaining(Consumer)
, as the entire point is to cycle forever.- Type Parameters:
T
- the type of the elements- Parameters:
elements
- the values to cycle- Returns:
- an Iterator that cycles through the given iterable without terminating
-
-