![JAR search and dependency download from the Maven repository](/logo.png)
autofixture.implementationdetails.CircularList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of autofixturegenerator Show documentation
Show all versions of autofixturegenerator Show documentation
An attempt to reimplement core features of a popular .NET anonymous value generator - AutoFixture - in
Java
package autofixture.implementationdetails;
import autofixture.interfaces.InstanceType;
import java.util.ArrayList;
import java.util.Random;
public class CircularList {
private static final Random RANDOM = new Random();
private final T[] enumConstants;
private int currentIndex = 0;
public CircularList(final T[] values) {
this.enumConstants = values.clone();
currentIndex = RANDOM.nextInt(values.length);
}
public static CircularList createFromEnum(final InstanceType type) {
final TListElement[] enumConstants = type.getEnumConstants();
return new CircularList<>(enumConstants);
}
public static CircularList fromCharactersIn(final String string) {
final ArrayList chars = new ArrayList<>();
string.chars().forEachOrdered(i -> chars.add((char) i));
return new CircularList<>(chars.toArray(new Character[chars.size()]));
}
public T next() {
if (currentIndex >= enumConstants.length) {
currentIndex = 0;
}
final T nextElement = enumConstants[currentIndex];
currentIndex++;
return nextElement;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy