-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBooleanList.java
More file actions
63 lines (53 loc) · 1.78 KB
/
BooleanList.java
File metadata and controls
63 lines (53 loc) · 1.78 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.List;
import java.util.ArrayList;
import java.util.Iterator;
public final class BooleanList implements Iterable<ListSymbol> {
private final List<ListSymbol> listRepresentation = new ArrayList<ListSymbol>();
private boolean frozen = false;
//adds a ListSymbol to the boolean list if the list hasn't been frozen
public final boolean add(ListSymbol listSymbol) {
if(! frozen){
return listRepresentation.add(listSymbol);
} else {
throw new UnsupportedOperationException("Cannot modify BooleanList after it has been frozen");
}
}
//builds a new Connector of Type type and adds it to the boolean list
public final boolean add(Type type){
Connector con = Connector.build(type);
return this.add(con);
}
//adds the contents of the parameter BooleanList and returns whether
//these contents were successfully added
protected final boolean append(BooleanList list){
boolean appendSuccess = true;
for(ListSymbol symbol:list)
//if any addition fails, appendSuccess will turn false
appendSuccess = appendSuccess && (this.add(symbol));
return appendSuccess;
}
public final void freeze() {
this.frozen = true;
}
public final List<ListSymbol> getListRepresentation() {
return new ArrayList<ListSymbol> (listRepresentation);
}
@Override
public String toString(){
StringBuilder s = new StringBuilder();
for(ListSymbol symbol: listRepresentation){
s.append(symbol.toString());
}
return s.toString();
}
public Iterator<ListSymbol> iterator(){
return getListRepresentation().iterator();
}
public final long complexity() {
long complexityCount = 0;
for(ListSymbol symbol: listRepresentation){
complexityCount += symbol.complexity();
}
return complexityCount;
}
}