package au.id.zancanaro.javacheck.statem; import java.util.Map; import java.util.NoSuchElementException; public abstract class CommandValue { private final int id; public CommandValue(int id) { this.id = id; } public abstract boolean isAbstract(); public abstract T get(); public int getId() { return id; } static class AbstractValue extends CommandValue { public AbstractValue(int id) { super(id); } @Override public boolean isAbstract() { return true; } @Override public T get() { throw new NoSuchElementException("Abstract values cannot be supplied"); } } static class ConcreteValue extends CommandValue { private final Map values; public ConcreteValue(int id, Map values) { super(id); this.values = values; } @Override public boolean isAbstract() { return true; } @Override @SuppressWarnings("unchecked") public T get() { if (values.containsKey(getId())) { return (T) values.get(getId()); } else { throw new NoSuchElementException("Concrete values cannot be supplied prior to being calculated"); } } } }