/** * Returns a shallow copy of this <tt>FixedsizeForgetfulHashSet</tt> instance: the elements * themselves are not cloned. * * @return a shallow copy of this set. */ @SuppressWarnings("unchecked") public FixedsizeForgetfulHashSet<E> clone() { try { FixedsizeForgetfulHashSet<E> newSet = (FixedsizeForgetfulHashSet<E>) super.clone(); newSet.map = map.clone(); return newSet; } catch (CloneNotSupportedException e) { throw new InternalError(); } }
/** * Returns an iterator over the elements in this set. The elements are returned in no particular * order. * * @return an Iterator over the elements in this set. * @see ConcurrentModificationException */ public Iterator<E> iterator() { return map.keySet().iterator(); }
/** * Tests if the set is full * * @return true, if the set is full (ie if adding any other entry will lead to removal of some * other entry to maintain the fixed-size property of the set). Returns false, otherwise */ public boolean isFull() { return map.isFull(); }
/** Removes all of the elements from this set. */ public void clear() { map.clear(); }
/** * Removes the specified element from this set if it is present. * * @param o object to be removed from this set, if present. * @return <tt>true</tt> if the set contained the specified element. */ public boolean remove(Object o) { return map.remove(o) == PRESENT; }
/** * Adds the specified element to this set if it is not already present. * * @param o element to be added to this set. * @return <tt>true</tt> if the set did not already contain the specified element. */ public boolean add(E o) { return map.put(o, PRESENT) == null; }
/** * Returns <tt>true</tt> if this set contains the specified element. * * @param o element whose presence in this set is to be tested. * @return <tt>true</tt> if this set contains the specified element. */ public boolean contains(Object o) { return map.containsKey(o); }
/** * Returns <tt>true</tt> if this set contains no elements. * * @return <tt>true</tt> if this set contains no elements. */ public boolean isEmpty() { return map.isEmpty(); }
/** * Returns the number of elements in this set (its cardinality). * * @return the number of elements in this set (its cardinality). */ public int size() { return map.size(); }