1 26 package org.jruby.util.collections; 27 28 import java.util.*; 29 30 36 public class WeakHashSet extends AbstractSet { 37 private static final Object MAP_VALUE = new Object (); 38 private WeakHashMap map; 39 40 public WeakHashSet() { 41 map = new WeakHashMap(); 42 } 43 44 public boolean add(Object o) { 45 Object previousValue = map.put(o, MAP_VALUE); 46 return previousValue == null; 47 } 48 49 public Iterator iterator() { 50 return map.keySet().iterator(); 51 } 52 53 public int size() { 54 return map.size(); 55 } 56 57 public boolean isEmpty() { 58 return map.isEmpty(); 59 } 60 61 public boolean contains(Object o) { 62 return map.containsKey(o); 63 } 64 65 public boolean remove(Object o) { 66 return map.remove(o) == MAP_VALUE; 67 } 68 69 public boolean removeAll(Collection collection) { 70 return map.keySet().removeAll(collection); 71 } 72 73 public boolean retainAll(Collection collection) { 74 return map.keySet().retainAll(collection); 75 } 76 77 public void clear() { 78 map.clear(); 79 } 80 81 } 82 | Popular Tags |