-
Notifications
You must be signed in to change notification settings - Fork 0
/
OperationList.java~
67 lines (46 loc) · 1.55 KB
/
OperationList.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
import java.util.LinkedList;
import java.util.Iterator;
public class OperationList extends LinkedList<OperationNode> implements Comparable{
public OperationList(){
super();
}
public OperationList(OperationList o){
for(OperationNode node : o){
this.add(new OperationNode(node.operator(), Factor.deepCopy(node.factor())));
}
}
public void add(char c, Factor f){
super.add(new OperationNode(c, f));
}
public int compareTo(Object o){
OperationList that = (OperationList)o;
int listCompare = (size()-that.size())/(Math.abs(size()-that.size())); //likely not most efficient way to do this... but watever for now
if(listCompare != 0)
return listCompare;
//if sizes are unequal
Iterator<OperationNode> thisIterator = iterator();
Iterator<OperationNode> thatIterator = that.iterator();
OperationNode thisPtr, thatPtr;
int ptrComp;
while(thisIterator.hasNext()){ //they should process parallel:
thisPtr = thisIterator.next();
thatPtr = thatIterator.next();
ptrComp = thisPtr.compareTo(thatPtr);
if(ptrComp < 0)
return -1;
else if(ptrComp > 0)
return 1;
}
return 0;
}
public String toString(){
StringBuilder toRet = new StringBuilder();
if(size() == 0)
return "";
Iterator<OperationNode> thisIter = iterator();
while(thisIter.hasNext()){
toRet.append(thisIter.next().toString());
}
return toRet.toString();
}
}