Ejemplo n.º 1
0
  /**
   * This method exists to make it easier to see when and where classes are changing the formula
   * This also serves another purpose by adding spaces and formatting when needed, something that
   * the normal setFormula() method cannot do.
   *
   * @param toAdd the information to add to the Formula : either operator or inputs
   * @exception SyntaxErrorException: this exception is thrown if the method is called trying to add
   *     an input where the last entry in the formula is an input already, or an operator following
   *     another operator. it also throws the exception if the first operator added is * or / and no
   *     inputs have been entered before. those are all errors that are dealt with in the AMT code,
   *     and the method should never be called in those instances.
   */
  public void addToFormula(String toAdd) throws SyntaxErrorException {
    if (toAdd.length() == 1) {
      addToFormula(toAdd.charAt(0));
      return;
    }
    // if the cell to add the operator in does not exist yet, create it
    if ((opList == null) || (nextEntry >= opList.size())) opList.add(new TreeCell());

    TreeCell currentCell = opList.get(nextEntry); // get the current cell that we will be using
    try {
      currentCell.addInputInCell(toAdd);
      if ((currentCell.getstatusCell() == TreeCell.RIGHT_COMPLETED)
          && ((currentCell.getcellValue().length() > 1))) nextEntry++;
      if ((currentCell.getstatusCell() == TreeCell.RIGHT_COMPLETED)
          && ((currentCell.getcellValue().length() == 1))
          && (currentCell.getrightSon() != null)) nextEntry++;
      this.addLeaveTotal();
    } catch (SyntaxErrorException e) {
      throw e;
    }
  }