Skip to content

A Round-Robin Iterator that traverses values in Round-Robin order.

Notifications You must be signed in to change notification settings

srchulo/RoundRobinIterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Round-Robin Iterator that traverses values in Round-Robin order.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages