KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > util > WeakHashSet


1 package org.objectweb.jac.util;
2
3 import java.lang.Cloneable JavaDoc;
4 import java.util.AbstractSet JavaDoc;
5 import java.util.Collection JavaDoc;
6 import java.util.Iterator JavaDoc;
7 import java.util.Set JavaDoc;
8 import java.util.WeakHashMap JavaDoc;
9
10
11 public class WeakHashSet extends AbstractSet JavaDoc
12     implements Set JavaDoc
13 {
14     private transient WeakHashMap map;
15
16     public WeakHashSet() {
17         map = new WeakHashMap();
18     }
19     public WeakHashSet(Collection JavaDoc c) {
20         map = new WeakHashMap(Math.max((int) (c.size()/.75f) + 1, 16));
21         addAll(c);
22     }
23     public WeakHashSet(int initialCapacity, float loadFactor) {
24         map = new WeakHashMap(initialCapacity, loadFactor);
25     }
26     public WeakHashSet(int initialCapacity) {
27         map = new WeakHashMap(initialCapacity);
28     }
29
30     public Iterator JavaDoc iterator() {
31         return map.keySet().iterator();
32     }
33
34     public int size() {
35         return map.size();
36     }
37     public boolean isEmpty() {
38         return map.isEmpty();
39     }
40
41     public boolean contains(Object JavaDoc o) {
42         return map.containsKey(o);
43     }
44
45     public boolean add(Object JavaDoc o) {
46         return map.put(o, Boolean.TRUE)==null;
47     }
48     public boolean remove(Object JavaDoc o) {
49         return map.remove(o)==Boolean.TRUE;
50     }
51     public void clear() {
52         map.clear();
53     }
54 }
55
Popular Tags