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  10/01/2000
9   */
10  public class UnaryOperator 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          // On recherche la position d'insertion de notre instance.
20          current = findLocation(current);
21  
22          if (current.getFather() == null) {
23              // On commence la saisie de la formule, on ajoute l'instance courante telle
24              // qu'elle dansla formule.
25              current.addChild(this);
26  
27          }
28          else { // 2 possibilitÈs s'offrent ? nous !!!
29              if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
30                  current.isTemplate()) {
31                  // Le cas classique (on va mÍme dire normal !!!)
32                  // La position d'insertion est un template.
33                  // On doit remplacer le template par l'instance courante (nos parenthËses)
34                  int rank = current.getRank();
35                  FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
36                  father.addChild(this, rank);
37                  father.removeChild(current);
38              }
39              else {
40                  // Le cas pas classique
41                  // La position d'insertion n'est pas un template.
42                  // On crÈÈ une multiplication implicite.
43                  current = (new Multiplication()).insert(current);
44                  // On insËre nos parenthËses
45                  current = insert(current);
46                  // On retourne le dernier point d'insertion.
47                  return current;
48              }
49          }
50  
51          // On ajoute un template ? notre opÈrateur.
52          VariableOrNumber template = new VariableOrNumber();
53          addChild(template);
54  
55          // On retourne le dernier point d'insertion.
56          return template;
57  
58      }
59      
60      /***
61      * The Creation of the corresponding linear expression of the formula.
62      */
63      public String createLinear(String linear) {
64          linear += getTheOperator();
65          linear = ((FormulaTreeStructure) getChild(0)).createLinear(linear);
66          return linear;
67      }
68  
69      /***
70      * Evaluates the instance.
71      */
72      public String evaluate() {
73          return getTheOperator() + ((FormulaTreeStructure) getChild(0)).evaluate();
74      }
75  }
76