1 package org.objectweb.jac.util; 2 3 import java.lang.Cloneable ; 4 import java.util.AbstractSet ; 5 import java.util.Collection ; 6 import java.util.Iterator ; 7 import java.util.Set ; 8 import java.util.WeakHashMap ; 9 10 11 public class WeakHashSet extends AbstractSet 12 implements Set 13 { 14 private transient WeakHashMap map; 15 16 public WeakHashSet() { 17 map = new WeakHashMap(); 18 } 19 public WeakHashSet(Collection 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 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 o) { 42 return map.containsKey(o); 43 } 44 45 public boolean add(Object o) { 46 return map.put(o, Boolean.TRUE)==null; 47 } 48 public boolean remove(Object o) { 49 return map.remove(o)==Boolean.TRUE; 50 } 51 public void clear() { 52 map.clear(); 53 } 54 } 55 | Popular Tags |