1 package org.shiftone.cache.util; 2 3 4 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 import java.util.List ; 8 import java.util.Set ; 9 10 11 15 public class WeakSet 16 { 17 18 private static final Log LOG = new Log(WeakSet.class); 19 private WeakMap weakMap = new WeakMap(); 20 private int count = 0; 21 22 public int size() 23 { 24 return weakMap.size(); 25 } 26 27 28 public boolean isEmpty() 29 { 30 return weakMap.isEmpty(); 31 } 32 33 34 public void add(Object obj) 35 { 36 weakMap.put(new Integer (count++), obj); 37 } 38 39 40 public void clear() 41 { 42 weakMap.clear(); 43 } 44 45 46 public Iterator iterator() 47 { 48 49 List list = new ArrayList (); 50 Set keys = weakMap.keySet(); 51 Iterator iterator = keys.iterator(); 52 53 while (iterator.hasNext()) 54 { 55 Object key = iterator.next(); 56 Object value = weakMap.get(key); 57 58 if (value != null) 59 { 60 list.add(value); 61 } 62 } 63 64 return list.iterator(); 65 } 66 } 67 | Popular Tags |