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

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

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

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;

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

public class ConstantDiceRoller implements DiceRoller {

  private final ImmutableList rolled;
  private boolean hasBeenRolled;

  public ConstantDiceRoller(List rolled) {
    this.rolled = ImmutableList.copyOf(rolled);
    checkArgument(rolled.size() == 3);
    hasBeenRolled = false;
  }

  @Override
  public void roll() {
    hasBeenRolled = true;
  }

  @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) {
    checkState(hasBeenRolled);
    return rolled.get(i);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy