1
2 package calculator.functions;
3
4 import calculator.Expression;
5 import calculator.atoms.*;
6 import visitor.Visitor;
7
8 public abstract class BinaryFunction implements Expression {
9
10 protected String symbol;
11 private Expression firstArg;
12 private Expression secondArg;
13
14 public BinaryFunction(Expression firstArg, Expression secondArg) {
15 this.firstArg = firstArg;
16 this.secondArg = secondArg;
17 }
18
19
20
21
22
23
24
25
26
27 public abstract Atom op(Real r1, Real r2);
28
29
30
31
32
33
34
35
36
37 public abstract Atom op(Complex c1, Complex c2);
38
39
40
41
42
43
44
45
46
47 public abstract Atom op(IntegerAtom i1, IntegerAtom i2);
48
49
50
51
52
53
54
55
56
57 public abstract Atom op(Rationnal q1, Rationnal q2);
58
59
60
61
62
63
64
65 public void accept(Visitor v) {
66 v.visit(this);
67 }
68
69 @Override
70 public boolean equals(Object o) {
71 if (o == null)
72 return false;
73 if (this == o)
74 return true;
75 if (getClass() != o.getClass())
76 return false;
77 BinaryFunction other = (BinaryFunction) o;
78 return this.firstArg.equals(other.getFirstArg()) && this.secondArg.equals(other.getSecondArg());
79 }
80
81 public String getSymbol() {
82 return symbol;
83 }
84
85 public void setSymbol(String symbol) {
86 this.symbol = symbol;
87 }
88
89 public Expression getFirstArg() {
90 return firstArg;
91 }
92
93 public void setFirstArg(Expression firstArg) {
94 this.firstArg = firstArg;
95 }
96
97 public Expression getSecondArg() {
98 return secondArg;
99 }
100
101 public void setSecondArg(Expression secondArg) {
102 this.secondArg = secondArg;
103 }
104 }