Package org.kiwiproject.collect
Class KiwiIterators
java.lang.Object
org.kiwiproject.collect.KiwiIterators
Utility methods for working with
Iterator instances. Analogous to Guava's Iterators-
Method Summary
Modifier and TypeMethodDescriptionstatic <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, based on Guava'sIterables.cycle(Iterable).
-
Method Details
-
cycleForever
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
Returns a thread-safe iterator that cycles indefinitely over the elements ofiterable, based on Guava'sIterables.cycle(Iterable). The differences from Guava are 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
-