1 package fr.ove.openmath.jome.model;
2
3 import java.util.*;
4 import fr.ove.openmath.jome.model.*;
5 import fr.ove.openmath.jome.model.evaluation.*;
6
7 /***
8 * @author © 1999 DIRAT Laurent
9 * @version 2.0 25/06/1999
10 */
11 public class BinaryOperator extends Operator {
12 /***
13 * Inserts the operator instance in the formula tree, from the current insertion position.
14 * (checks the priorities and goes up in the tree if necessary).
15 *
16 * @param ope the current insertion position.
17 * @return the new insertion position.
18 */
19 public FormulaTreeStructure insert(FormulaTreeStructure current) {
20 VariableOrNumber template;
21
22
23 current = findLocation(current);
24
25
26
27
28
29
30
31 current.addChild(this);
32
33 if ((current.getFather() == null) && (current.getNbChildren() == 1)) {
34 template = new VariableOrNumber();
35 addChild(template);
36 }
37 else {
38 FormulaTreeStructure fts = (FormulaTreeStructure) current.getChild(getRank() - 1);
39
40
41 addChild(fts);
42
43
44
45
46 int prio = fts.getAsOperatorPriority();
47 if (prio == resourcesManager.getAsOperatorPriority("bracketPriorities")) {
48 prio = getAsOperatorPriority();
49 if (prio == resourcesManager.getAsOperatorPriority("dividePriorities"))
50 ((Bracket) fts).setIsVisible(false);
51 else
52 ((Bracket) fts).setIsVisible(true);
53 }
54
55
56
57
58 current.removeChild(fts);
59 }
60
61
62 template = new VariableOrNumber();
63 addChild(template);
64
65
66 return template;
67 }
68
69 /***
70 * The Creation of the corresponding linear expression of the formula.
71 */
72 public String createLinear(String linear) {
73 linear = ((FormulaTreeStructure) getChild(0)).createLinear(linear);
74 linear += getTheOperator();
75 linear = ((FormulaTreeStructure) getChild(1)).createLinear(linear);
76 return linear;
77 }
78
79 /***
80 * Evaluates the instance.
81 */
82 public String evaluate() {
83 return Evaluator.evaluate(((FormulaTreeStructure) getChild(0)).evaluate(),
84 ((FormulaTreeStructure) getChild(1)).evaluate(),
85 getTheOperator());
86 }
87
88 }