01: package org.shiftone.cache.util;
02:
03: import java.util.ArrayList;
04: import java.util.Iterator;
05: import java.util.List;
06: import java.util.Set;
07:
08: /**
09: * @version $Revision: 1.3 $
10: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
11: */
12: public class WeakSet {
13:
14: private static final Log LOG = new Log(WeakSet.class);
15: private WeakMap weakMap = new WeakMap();
16: private int count = 0;
17:
18: public int size() {
19: return weakMap.size();
20: }
21:
22: public boolean isEmpty() {
23: return weakMap.isEmpty();
24: }
25:
26: public void add(Object obj) {
27: weakMap.put(new Integer(count++), obj);
28: }
29:
30: public void clear() {
31: weakMap.clear();
32: }
33:
34: public Iterator iterator() {
35:
36: List list = new ArrayList();
37: Set keys = weakMap.keySet();
38: Iterator iterator = keys.iterator();
39:
40: while (iterator.hasNext()) {
41: Object key = iterator.next();
42: Object value = weakMap.get(key);
43:
44: if (value != null) {
45: list.add(value);
46: }
47: }
48:
49: return list.iterator();
50: }
51: }
|