package fr.umlv.calc;

public class OpOrValue {
  public static final int OP_NONE = 0;
  public static final int OP_ADD = 1;
  public static final int OP_SUB = 2;
  
  private final int value;
  private final int operator;
  private final OpOrValue left;
  private final OpOrValue right;
  
  private OpOrValue(int value, int operator, OpOrValue left, OpOrValue right) {
    this.value = value;
    this.operator = operator;
    this.left = left;
    this.right = right;
  }
  
  public OpOrValue(int value) {
    this(value, OP_NONE, null, null);
  }
  public OpOrValue(int operator, OpOrValue left, OpOrValue right) {
    // bugs lies here
    this(0, operator, left, right); 
  }
  
  public int getOperator() {
    return operator;
  }
  public int getValue() {
    if (operator != OP_NONE) {
      throw new IllegalStateException();
    }
    return value;
  }
  public OpOrValue getLeft() {
    if (operator == OP_NONE) {
      throw new IllegalStateException();
    }
    return left;
  }
  public OpOrValue getRight() {
    if (operator == OP_NONE) {
      throw new IllegalStateException();
    }
    return right;
  }
}
