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

io.github.oliviercailloux.g421.PredictedDiceRoller Maven / Gradle / Ivy

The newest version!
package io.github.oliviercailloux.g421;

import com.google.common.collect.ImmutableList;
import java.util.List;

public class PredictedDiceRoller implements DiceRoller {

  private final ImmutableList> rolls;
  private int current;

  public PredictedDiceRoller(List> rolls) {
    this.rolls = rolls.stream().map(ImmutableList::copyOf).collect(ImmutableList.toImmutableList());
    current = -1;
  }

  @Override
  public void roll() {
    ++current;
  }

  @Override
  public int first() throws IllegalStateException {
    return ith(0);
  }

  @Override
  public int second() throws IllegalStateException {
    return ith(1);
  }

  @Override
  public int third() throws IllegalStateException {
    return ith(2);
  }

  private int ith(int i) {
    return rolls.get(current).get(i);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy