-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerm.java~
121 lines (81 loc) · 2.44 KB
/
Term.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.*;
//list of factors
public class Term implements Comparable{
private boolean sign;
private static boolean firstPushAfterExp;
private BinaryTreeList<Factor> factors;
private LinkedList<Constant> constants;
public boolean isEmpty(){
return factors.size() + constants.size() != 0;
}
public Factor addFactor(Factor f){
System.out.println(f+" was added.");
if(f instanceof Constant)
constants.add((Constant)f);
else
factors.add(f);
System.out.println("And the term looks like: "+this);
System.out.println("The tree size is: " +factors.size());
return f;
}
public int size(){
return factors.size() + (constants != null ? constants.size() : 0);
}
public void addFactors(List<? extends Factor> factors){
Iterator<? extends Factor> iter = factors.iterator();
while(iter.hasNext())
addFactor(iter.next());
}
public void setSign(boolean sign){
this.sign = sign;
}
public List<Constant> constants(){
return constants;
}
public Term(){
factors = new BinaryTreeList<Factor>();
constants = new LinkedList<Constant>();
this.sign = true;
}
public Term(Term t){
factors = new BinaryTreeList<Factor>();
constants = new LinkedList<Constant>();
for(Factor f : factors.asList()){
factors.add(Factor.deepCopy(f));
}
}
public List<Factor> factors(){
return factors.asList();
}
public String toString(){
// System.out.println("In the Term toString() method.");
StringBuilder termString = new StringBuilder();
if(constants != null){
for(Constant c : constants)
termString.append(c.toString());
}
if(factors != null){
for(Factor f : factors.asList()){
// System.out.println("~Term: Appending the factors of this term.");
termString.append(f.toString());
}
}
return termString.toString();
}
public boolean getSign(){
return this.sign;
}
public int compareTo(Object o){
Term that = (Term)o;
return 0; /*factorList.compareTo(that.factors()); */
}
public void removeFactor(Factor f){
factors.remove(f);
}
public List<Factor> allFactors(){
LinkedList<Factor> toReturn = new LinkedList<Factor>();
toReturn.addAll(constants);
toReturn.addAll(factors.asList());
return toReturn;
}
}