/** * 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; }
/** * 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; }
/** * The returned array may contain <code>null</code> elements! * @inheritDoc */ public Object[] toArray(Object a[]) { if (a.length < size) { a = (Object[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); } for (int i = 0; i < size; i++) { a[i] = elementData[i].get(); } if (a.length > size) { a[size] = null; } return a; }
/** * The returned array may contain <code>null</code> elements! * {@inheritDoc} */ public Object[] toArray(Object a[]) { if (a.length < size) { a = (Object[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); } for (int i = 0; i < size; i++) { a[i] = elementData[i].get(); } if (a.length > size) { a[size] = null; } return a; }
/** * 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; }
/** * The returned array may contain <code>null</code> elements! * {@inheritDoc} */ public Object[] toArray(Object a[]) { if (a.length < size) { a = (Object[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); } for (int i = 0; i < size; i++) { a[i] = elementData[i].get(); } if (a.length > size) { a[size] = null; } return a; }
/** * 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; }
/** * The returned array may contain <code>null</code> elements! * {@inheritDoc} */ public Object[] toArray(Object a[]) { if (a.length < size) { a = (Object[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); } for (int i = 0; i < size; i++) { a[i] = elementData[i].get(); } if (a.length > size) { a[size] = null; } return a; }
/** * Returns <code>true</code> if this collection contains <code>o</code>. * * @param o element whose presence in this collection is to be tested. * @return <code>true</code> if this collection contains the specified * element */ public boolean contains(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { return true; } } return false; }
/** * Returns <code>true</code> if this collection contains <code>o</code>. * * @param o element whose presence in this collection is to be tested. * @return <code>true</code> if this collection contains the specified * element */ public boolean contains(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { return true; } } return false; }
/** * Returns <code>true</code> if this collection contains <code>o</code>. * * @param o element whose presence in this collection is to be tested. * @return <code>true</code> if this collection contains the specified * element */ public boolean contains(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { return true; } } return false; }
/** * Returns <code>true</code> if this collection contains <code>o</code>. * * @param o element whose presence in this collection is to be tested. * @return <code>true</code> if this collection contains the specified * element */ public boolean contains(Object o) { for (int i = 0; i < size; i++) { if (elementData[i].get() == o) { return true; } } return false; }
/** * Returns an array containing all of the elements in this collection. The * returned array may contain <code>null</code> elements! * * @return an array containing all of the elements in this collection. */ public Object[] toArray() { Object[] result = new Object[size]; for (int i = 0; i < result.length; i++) { result[i] = elementData[i].get(); } return result; }
/** * Returns an array containing all of the elements in this collection. The * returned array may contain <code>null</code> elements! * * @return an array containing all of the elements in this collection. */ public Object[] toArray() { Object[] result = new Object[size]; for (int i = 0; i < result.length; i++) { result[i] = elementData[i].get(); } return result; }
/** * Returns an array containing all of the elements in this collection. The * returned array may contain <code>null</code> elements! * * @return an array containing all of the elements in this collection. */ public Object[] toArray() { Object[] result = new Object[size]; for (int i = 0; i < result.length; i++) { result[i] = elementData[i].get(); } return result; }
/** * Returns an array containing all of the elements in this collection. The * returned array may contain <code>null</code> elements! * * @return an array containing all of the elements in this collection. */ public Object[] toArray() { Object[] result = new Object[size]; for (int i = 0; i < result.length; i++) { result[i] = elementData[i].get(); } return result; }