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
20 current = findLocation(current);
21
22 if (current.getFather() == null) {
23
24
25 current.addChild(this);
26
27 }
28 else {
29 if ((current.getAsOperatorPriority() == resourcesManager.getAsOperatorPriority("constantPriorities")) &&
30 current.isTemplate()) {
31
32
33
34 int rank = current.getRank();
35 FormulaTreeStructure father = (FormulaTreeStructure) current.getFather();
36 father.addChild(this, rank);
37 father.removeChild(current);
38 }
39 else {
40
41
42
43 current = (new Multiplication()).insert(current);
44
45 current = insert(current);
46
47 return current;
48 }
49 }
50
51
52 VariableOrNumber template = new VariableOrNumber();
53 addChild(template);
54
55
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