View Javadoc

1   package fr.ove.openmath.jome.model;
2   
3   import java.util.*;
4   import fr.ove.openmath.jome.model.*;
5   
6   /***
7   * @author © 2000 DIRAT Laurent
8   * @version 2.1  24/02/2000
9   */
10  public class UnaryPostfixedOperator extends Operator {
11      /***
12      * Inserts the operator instance in the formula tree, from the current insertion position.
13      * (checks the priorities and goes up in the tree if necessary).
14      *
15      * @param ope the current insertion position.
16      * @return the new insertion position.
17      */
18      public FormulaTreeStructure insert(FormulaTreeStructure current) {
19          VariableOrNumber template;
20          
21          // On cherche la position d'insertion de notre operateur
22          current = findLocation(current);
23          
24          // On ajoute l'opÈrateur comme fils ? l'opÈrateur courant
25          current.addChild(this);
26  
27          if ((current.getFather() == null) && (current.getNbChildren() == 1))
28              addChild(new VariableOrNumber());
29          else {
30              FormulaTreeStructure fts = (FormulaTreeStructure) current.getChild(getRank() - 1);
31              // ? cause des prioritÈs sur les opÈrateurs, on ajoute comme fils l'opÈrateur
32              // dont le rang est juste infÈrieur ? notre instance
33              addChild(fts);
34              
35              // on enlËve l'opÈrateur qu'on a fait "descendre", de la liste
36              // de son prÈcÈdent pËre (son grand pËre maintenant)
37              current.removeChild(fts);
38          }
39          
40          FormulaTreeStructure child = (FormulaTreeStructure) getChild(0);
41          if (child.getResourceIdentifier().equals("OPEN_PAREN"))
42              ((Bracket) child).setIsVisible(true); // Dans le cas o? la ! est fille d'une division, les parenthËses
43              // auront ÈtÈ rendues invisibles d'abord.
44              
45  
46          // On retourne la refÈrence de l'instance.
47          return this;
48      }
49      
50      /***
51      * The Creation of the corresponding linear expression of the formula.
52      */
53      public String createLinear(String linear) {
54          linear = ((FormulaTreeStructure) getChild(0)).createLinear(linear);
55          linear += getTheOperator();
56          return linear;
57      }
58  
59      /***
60      * Evaluates the instance.
61      */
62      public String evaluate() {
63          return ((FormulaTreeStructure) getChild(0)).evaluate() + getTheOperator();
64      }
65  }
66