de.janno.evaluator.dice.random.GivenNumberSupplier Maven / Gradle / Ivy
The newest version!
package de.janno.evaluator.dice.random;
import com.google.common.annotations.VisibleForTesting;
import de.janno.evaluator.dice.DieId;
import lombok.NonNull;
import java.util.*;
@VisibleForTesting
public class GivenNumberSupplier implements NumberSupplier {
final private Deque results;
public GivenNumberSupplier() {
this(Collections.emptyList());
}
public GivenNumberSupplier(Integer... results) {
this(Arrays.asList(results));
}
public GivenNumberSupplier(Collection results) {
if (results == null) {
this.results = new ArrayDeque<>();
} else {
this.results = new ArrayDeque<>(results);
}
}
@Override
public int get(int minExcl, int maxIncl, @NonNull DieId dieId) {
if (results.isEmpty()) {
return maxIncl;
}
return results.pop();
}
}