More classes for galois
[IRC.git] / Robust / src / ClassLibrary / MGC / gnu / HashSet.java
1 public class HashSet implements Set {
2   HashMap map;
3   HashSet() {
4     map=new HashMap();
5   }
6   HashSet(int initialCapacity) {
7     map=new HashMap(initialCapacity);
8   }
9   HashSet(int initialCapacity, float loadFactor) {
10     map=new HashMap(initialCapacity, loadFactor);
11   }
12   public boolean add(Object o) {
13     return (map.put(o, this)==null);
14   }
15   public boolean addAll(Collection c) {
16     Iterator it = c.iterator();
17     while(it.hasNext()) {
18       if(!this.add(it.next())) {
19         return false;
20       }
21     }
22     return true;
23   }
24   public boolean remove(Object o) {
25     return (map.remove(o)!=null);
26   }
27   boolean removeAll(Collection c) {
28     Iterator it = c.iterator();
29     while(it.hasNext()) {
30       if(!this.remove(it.next())) {
31         return false;
32       }
33     }
34     return true;
35   }
36   public boolean isEmpty() {
37     return map.isEmpty();
38   }
39   public void clear() {
40     map.clear();
41   }
42   public boolean contains(Object o) {
43     return map.containsKey(o);
44   }
45   public boolean containsAll(Collection c) {
46     Iterator it = c.iterator();
47     while(it.hasNext()) {
48       if(!this.contains(it.next())) {
49         return false;
50       }
51     }
52     return true;
53   }
54   public int size() {
55     return map.size();
56   }
57   public Iterator iterator() {
58     return map.iterator(0);
59   }
60 }