/** * Return the size of the set. * @return The size of the set. */ public int size() { expungeStaleEntries(); return set.size(); }
/** * Returns true if this set contains no elements. * @return true if this set contains no elements. */ public boolean isEmpty() { expungeStaleEntries(); return set.isEmpty(); }
/** * Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned. * @return A shallow copy of this set. */ public Object clone() { expungeStaleEntries(); try { return super.clone(); } catch(CloneNotSupportedException e) { throw new InternalError(); } }
/** * Removes the given element from this set if it is present. * @param obj Object to be removed from this set, if present. * @return true if the set contained the specified element. */ public boolean remove(final Object obj) { if(obj==null) throw new IllegalArgumentException("Must not be null."); expungeStaleEntries(); return set.remove(new WeakObject(obj)); }
/** * Add an element to the set. * @param obj Element to add to the set. * @return True if the element was added. */ public boolean add(final Object obj) { if(obj==null) throw new IllegalArgumentException("Must not be null."); expungeStaleEntries(); return set.add(new WeakObject(obj, queue)); }
/** * Returns true if this set contains the specified element. * @param obj Element whose presence in this set is to be tested. * @return true if this set contains the specified element. */ public boolean contains(final Object obj) { if(obj==null) throw new IllegalArgumentException("Must not be null."); expungeStaleEntries(); return set.contains(new WeakObject(obj)); }
expungeStaleEntries(); return new Iterator()
/** * Perform special handling on serialization. */ protected Object writeReplace() throws ObjectStreamException { // Extract weak references as they are not serializable. expungeStaleEntries(); this.serialized_set = SCollection.createHashSet(); for(Iterator it=set.iterator(); it.hasNext(); ) { Object next = ((WeakObject)it.next()).get(); if(next!=null) serialized_set.add(next); } return this; }