-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerm.java
More file actions
63 lines (53 loc) · 1.58 KB
/
Term.java
File metadata and controls
63 lines (53 loc) · 1.58 KB
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
56
57
58
59
60
61
62
63
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
public class Term extends AbstractTreeSymbol {
private final Symbol subexpression;
private Term(Symbol subexpression){
super(subexpression.getType());
this.subexpression = subexpression;
}
public static final Term build(Symbol subexpression) {
Set<Type> allowedTypes = new HashSet<>();
allowedTypes.add(Type.VARIABLE);
allowedTypes.add(Type.EXPRESSION);
validateSubexpression(subexpression, allowedTypes, "Terms must consist of either a single VARIABLE or an EXPRESSION");
return new Term(subexpression);
}
@Override
public Type getType() {
return Type.TERM;
}
final Symbol getSymbol() {
return subexpression;
}
@Override
public BooleanList toList() {
if(subexpression.getType() == Type.VARIABLE){
return subexpression.toList();
} else { //we know it is an EXPRESSION because build() only allows Variables and Expressions
BooleanList listRepresentation = new BooleanList();
listRepresentation.add(Type.OPEN);
//adds everything in BooleanList of subexpression
listRepresentation.append(subexpression.toList());
listRepresentation.add(Type.CLOSE);
return listRepresentation;
}
}
@Override
public String toString() {
return this.toList().toString();
}
@Override
public Symbol simplified(){
return build(subexpression.simplified());
}
@Override
public Optional<Symbol> subterm() {
return Optional.of(subexpression);
}
@Override
public long complexity() {
return subexpression.complexity();
}
}