Exemplo n.º 1
0
  /**
   * Method that copies the content of a TreeCell given as parameter to the current formula
   *
   * @param cellCopy the main operator or first input to copy
   * @throws SyntaxErrorException the formula is not syntactically correct
   */
  public void copyTreeCell(TreeCell cellCopy) throws SyntaxErrorException {
    if (cellCopy != null) {
      if (cellCopy.getleftSon() != null) copyTreeCell(cellCopy.getleftSon());

      String cellValue = cellCopy.getcellValue(); // holds the value of the current cell

      if (cellValue != null)
        if (cellValue.length() > 1) addToFormula(cellValue);
        else addToFormula(cellValue.charAt(0));
      if (cellCopy.getrightSon() != null) copyTreeCell(cellCopy.getrightSon());
    }
  }
Exemplo n.º 2
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;
    }
  }
Exemplo n.º 3
0
 /**
  * method will set the current cell to all the values of the leftSon, causing the leftSon to
  * replace the currentCell
  */
 public void swapWithLeftSon() {
   setrightSon(leftSon.getrightSon());
   setcellValue(leftSon.getcellValue());
   setstatusCell(leftSon.getstatusCell());
   setleftSon(leftSon.getleftSon());
 }