1 |
torben |
433 |
package dk.thoerup.traininfo.util; |
2 |
|
|
|
3 |
|
|
import java.util.Set; |
4 |
|
|
import java.util.TreeSet; |
5 |
|
|
|
6 |
|
|
public class IntSet { |
7 |
|
|
private Set<Integer> ints = new TreeSet<Integer>(); |
8 |
|
|
|
9 |
|
|
public boolean hasInt(int i) { |
10 |
|
|
return ints.contains(i); |
11 |
|
|
} |
12 |
|
|
|
13 |
|
|
public void add(int i) { |
14 |
|
|
ints.add(i); |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
public void remove(int i) { |
18 |
|
|
ints.remove(i); |
19 |
|
|
} |
20 |
|
|
|
21 |
|
|
public String toString() { |
22 |
|
|
StringBuffer sb = new StringBuffer(); |
23 |
|
|
|
24 |
|
|
for (int i : ints) { |
25 |
|
|
if (sb.length() > 0) { |
26 |
|
|
sb.append(","); |
27 |
|
|
} |
28 |
|
|
sb.append(i); |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
return sb.toString(); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
public void fromString(String intStr) { |
35 |
|
|
ints.clear(); |
36 |
|
|
String parts[] = intStr.split(","); |
37 |
|
|
for (String istr : parts) { |
38 |
|
|
ints.add( Integer.parseInt(istr)); |
39 |
|
|
} |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
} |