A Round-Robin Iterator that traverses values in Round-Robin order.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/main/java/com/srchulo/roundrobin
.gitignore
README.md
pom.xml

README.md

RoundRobinIterator

A Round-Robin Iterator that traverses values in Round-Robin order, and can add and remove values in constant time.

Javadoc

RoundRobinIterator

Maven

<dependency>
    <groupId>com.srchulo.roundrobin</groupId>
    <artifactId>RoundRobinIterator</artifactId>
    <version>1.5</version>
</dependency>

Sample usage

RoundRobinIterator<String> roundRobinIterator = 
    RoundRobinIterator.newInstance(ImmutableList.of("a", "b", "c"));

for (String letter : roundRobinIterator) {
    System.out.println(letter);
}

This prints

a

b

c

a

b

c

a

b

c

.

.

.

RoundRobinKeyValueIterator

RoundRobinKeyValueIterator<Integer, String> roundRobinKeyValueIterator = 
    RoundRobinKeyValueIterator
        .newInstance(
            ImmutableList.of(
                new Pair(1, "a"), 
                new Pair(2, "b"), 
                new Pair(3, "c")));

boolean removedA;
for (String letter : roundRobinKeyValueIterator) {
    System.out.println(letter);
    
    if (!removedA) {
        roundRobinKeyValueIterator.remove(/* key= */ 1);
        removedA = true;
    }
}

This prints

a

b

c

b

c

b

c

.

.

.

Elements can also be removed by calling remove() after calling next() like any other iterator. The above example was just to demonstrate how values can be removed by their keys.