-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnaryExpression.java
55 lines (47 loc) · 1.52 KB
/
UnaryExpression.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.ArrayList;
import java.util.List;
/**
* UnaryExpression represents expression that are formed from one expression.
* @author Yossi Maatook.
*/
public abstract class UnaryExpression extends BaseExpression {
private Expression expression;
/**
* Constructor.
* @param e - the expression forming the unary expression.
*/
public UnaryExpression(Expression e) {
this.expression = e;
}
/**
* Returns the expression forming the unary expression.
* @return the expression forming the unary expression.
*/
public Expression getExpression() {
return this.expression;
}
@Override
public String toString() {
return (getExpressionSign() + "(" + this.expression.toString() + ")");
}
@Override
public List<String> getVariables() {
return super.getVariables();
}
@Override
public Expression assign(String var, Expression e) {
return createInstance(this.expression.assign(var, e));
}
@Override
protected ArrayList<Expression> getExpressions() {
ArrayList<Expression> list = new ArrayList<>();
list.add(this.expression);
return list;
}
/**
* Return an instance of the expression that is formed form A given expression.
* @param e - the expression forming the unary expression.
* @return expression formed from the given expression.
*/
protected abstract Expression createInstance(Expression e);
}