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 op
  */
 public void addToFormula(char op) throws SyntaxErrorException {
   // 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 {
     if (((op == '/') || (op == '*')) && (nextEntry > 0)) {
       if ((opList.get(nextEntry).getleftSon() == null)
           && (opList.get(nextEntry - 1).getcellValue().length() == 1)) {
         opList.remove(nextEntry);
         nextEntry--;
         currentCell = opList.get(nextEntry);
         currentCell.addOpAndReform(op);
       } else if ((opList.get(nextEntry).getcellValue() == null)
           && (opList.get(nextEntry - 1).getcellValue().length() >= 1)) {
         // this is the first operator to be entered, the first entry being an input.
         opList.remove(nextEntry);
         nextEntry--;
         currentCell = opList.get(nextEntry);
         currentCell.setleftSon(new TreeCell(currentCell.getcellValue()));
         currentCell.setrightSon(null);
         currentCell.setcellValue(op + "");
         currentCell.setstatusCell(TreeCell.LEFT_COMPLETED);
       }
     } else {
       currentCell.addOpInCell(op);
     }
   } catch (SyntaxErrorException e) {
     throw e;
   }
 }
Ejemplo n.º 2
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());
 }