com.flextrade.jfixture.utility.CircularList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfixture Show documentation
Show all versions of jfixture Show documentation
JFixture is an open source library based on the popular .NET library, AutoFixture
package com.flextrade.jfixture.utility;
import java.util.ArrayList;
import java.util.List;
/*
* Very basic implementation of a circular list to be used internally
*/
public class CircularList {
private List source;
private int currentIndex = 0;
public CircularList(List source) {
if(source == null)
throw new IllegalArgumentException("source is null");
if(source.size() == 0)
throw new IllegalArgumentException("source has zero elements");
this.source = new ArrayList(source);
}
public T next() {
if(currentIndex == source.size())
currentIndex = 0;
T value = source.get(currentIndex);
currentIndex++;
return value;
}
}