/** * Adds object <code>o</code> to this collection. * * @param o the object to add. * @return always <code>true</code> as this collection allows duplicates. * @throws NullPointerException if <code>o</code> is <code>null</code>. */ public boolean add(Object o) { if (o == null) { throw new NullPointerException("Object must not be null"); } // poll refQueue for a slot we can reuse WeakRef ref = (WeakRef) refQueue.poll(); if (ref != null) { elementData[ref.index] = new WeakRef(o, ref.index); cleanQueue(); } else if (!emptySlots.isEmpty()) { int idx = emptySlots.nextSetBit(0); elementData[idx] = new WeakRef(o, idx); emptySlots.clear(idx); } else { ensureCapacity(size + 1); elementData[size++] = new WeakRef(o, size - 1); } return true; }
/** * Adds object <code>o</code> to this collection. * * @param o the object to add. * @return always <code>true</code> as this collection allows duplicates. * @throws NullPointerException if <code>o</code> is <code>null</code>. */ public boolean add(Object o) { if (o == null) { throw new NullPointerException("Object must not be null"); } // poll refQueue for a slot we can reuse WeakRef ref = (WeakRef) refQueue.poll(); if (ref != null) { elementData[ref.index] = new WeakRef(o, ref.index); cleanQueue(); } else if (!emptySlots.isEmpty()) { int idx = emptySlots.nextSetBit(0); elementData[idx] = new WeakRef(o, idx); emptySlots.clear(idx); } else { ensureCapacity(size + 1); elementData[size++] = new WeakRef(o, size - 1); } return true; }
/** * Adds object <code>o</code> to this collection. * * @param o the object to add. * @return always <code>true</code> as this collection allows duplicates. * @throws NullPointerException if <code>o</code> is <code>null</code>. */ public boolean add(Object o) { if (o == null) { throw new NullPointerException("Object must not be null"); } // poll refQueue for a slot we can reuse WeakRef ref = (WeakRef) refQueue.poll(); if (ref != null) { elementData[ref.index] = new WeakRef(o, ref.index); cleanQueue(); } else if (!emptySlots.isEmpty()) { int idx = emptySlots.nextSetBit(0); elementData[idx] = new WeakRef(o, idx); emptySlots.clear(idx); } else { ensureCapacity(size + 1); elementData[size++] = new WeakRef(o, size - 1); } return true; }
/** * Adds object <code>o</code> to this collection. * * @param o the object to add. * @return always <code>true</code> as this collection allows duplicates. * @throws NullPointerException if <code>o</code> is <code>null</code>. */ public boolean add(Object o) { if (o == null) { throw new NullPointerException("Object must not be null"); } // poll refQueue for a slot we can reuse WeakRef ref = (WeakRef) refQueue.poll(); if (ref != null) { elementData[ref.index] = new WeakRef(o, ref.index); cleanQueue(); } else if (!emptySlots.isEmpty()) { int idx = emptySlots.nextSetBit(0); elementData[idx] = new WeakRef(o, idx); emptySlots.clear(idx); } else { ensureCapacity(size + 1); elementData[size++] = new WeakRef(o, size - 1); } return true; }
/** * Removes the object <code>o</code> from this collection if it is present. * * @param o the object to remove. * @return <code>true</code> if this collection changed as a result of the * call. */ public boolean remove(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { emptySlots.set(i); // overwrite entry with dummy ref elementData[i] = new WeakRef(null, i); return true; } } return false; }
/** * Removes the object <code>o</code> from this collection if it is present. * * @param o the object to remove. * @return <code>true</code> if this collection changed as a result of the * call. */ public boolean remove(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { emptySlots.set(i); // overwrite entry with dummy ref elementData[i] = new WeakRef(null, i); return true; } } return false; }
/** * Removes the object <code>o</code> from this collection if it is present. * * @param o the object to remove. * @return <code>true</code> if this collection changed as a result of the * call. */ public boolean remove(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { emptySlots.set(i); // overwrite entry with dummy ref elementData[i] = new WeakRef(null, i); return true; } } return false; }
/** * Removes the object <code>o</code> from this collection if it is present. * * @param o the object to remove. * @return <code>true</code> if this collection changed as a result of the * call. */ public boolean remove(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { emptySlots.set(i); // overwrite entry with dummy ref elementData[i] = new WeakRef(null, i); return true; } } return false; }