forked from inesxferreira/SD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPositionsList.java
51 lines (45 loc) · 1.28 KB
/
PositionsList.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
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
public class PositionsList extends ArrayList<Positions> {
public void serialize(DataOutputStream out) throws IOException {
out.writeInt(this.size());
for (Positions c : this) {
c.serialize(out);
}
}
public static PositionsList deserialize(DataInputStream in) throws IOException {
PositionsList l = new PositionsList();
int size = in.readInt();
for (int i = 0; i < size; i++) {
l.add(Positions.deserialize(in));
}
return l;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (Positions p : this) {
sb.append(p.toString()).append(";");
}
return sb.toString();
}
public boolean contains(Positions o) {
for(Positions p : this) {
if(o.equals(p)) {
return true;
}
}
return false;
}
public boolean remove(Positions o) {
for(int i = 0; i < this.size(); i++) {
if(this.get(i).equals(o)) {
this.remove(i);
return true;
}
}
return false;
}
}