All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.flextrade.jfixture.utility.CircularList Maven / Gradle / Ivy

Go to download

JFixture is an open source library based on the popular .NET library, AutoFixture

There is a newer version: 2.7.2
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy