/** {@inheritDoc} */ @Override public boolean addAll(@Nullable Collection<? extends E> c) { boolean res = false; if (!F.isEmpty(c)) { assert c != null; for (E e : c) { res |= add(e); } } return res; }
/** * Constructs a new set containing the elements in the specified * collection, with default load factor and an initial * capacity sufficient to contain the elements in the specified collection. * * @param c Collection to add. */ public GridConcurrentWeakHashSet(Collection<E> c) { this(c.size()); addAll(c); }
/** {@inheritDoc} */ @SuppressWarnings({"SimplifiableIfStatement"}) @Override public boolean add(E e) { A.notNull(e, "e"); removeStale(); if (!contains(e)) return store.add(fact.apply(e)); return false; }
/** {@inheritDoc} */ @Override public boolean isEmpty() { removeStale(); return store.isEmpty(); }
final Collection<SampleBean> set = new GridConcurrentWeakHashSet<>();
/** {@inheritDoc} */ @Override public boolean removeAll(@Nullable Collection<?> c) { boolean res = false; if (!F.isEmpty(c)) { assert c != null; for (Object o : c) { res |= remove(o); } } return res; }
/** * Removes stale references. */ private void removeStale() { WeakReferenceElement<E> ref; while ((ref = (WeakReferenceElement<E>) gcQ.poll()) != null) { store.remove(ref); onGc(ref.get()); } }
/** {@inheritDoc} */ @Override public Object[] toArray() { return toArray(EMPTY_ARR); }
/** {@inheritDoc} */ @Override public boolean containsAll(@Nullable Collection<?> c) { if (F.isEmpty(c)) return false; assert c != null; for (Object o : c) { if (!contains(o)) return false; } return true; }
/** {@inheritDoc} */ @SuppressWarnings({"SuspiciousToArrayCall"}) @Override public <T> T[] toArray(T[] a) { removeStale(); Collection<E> elems = new LinkedList<>(); for (WeakReferenceElement<E> ref : store) { E e = ref.get(); if (e != null) elems.add(e); } return elems.toArray(a); }
Collection<Integer> set = new GridConcurrentWeakHashSet<>();
/** {@inheritDoc} */ @Override public boolean removeAll(@Nullable Collection<?> c) { boolean res = false; if (!F.isEmpty(c)) { assert c != null; for (Object o : c) { res |= remove(o); } } return res; }
/** * Removes stale references. */ private void removeStale() { WeakReferenceElement<E> ref; while ((ref = (WeakReferenceElement<E>) gcQ.poll()) != null) { store.remove(ref); onGc(ref.get()); } }
/** {@inheritDoc} */ @SuppressWarnings({"ToArrayCallWithZeroLengthArrayArgument"}) @Override public Object[] toArray() { return toArray(EMPTY_ARR); }
/** {@inheritDoc} */ @Override public boolean containsAll(@Nullable Collection<?> c) { if (F.isEmpty(c)) return false; assert c != null; for (Object o : c) { if (!contains(o)) return false; } return true; }
/** {@inheritDoc} */ @Override public int size() { removeStale(); return store.size(); }
/** {@inheritDoc} */ @SuppressWarnings({"SimplifiableIfStatement"}) @Override public boolean add(E e) { A.notNull(e, "e"); removeStale(); if (!contains(e)) return store.add(fact.apply(e)); return false; }
final Collection<SampleBean> set = new GridConcurrentWeakHashSet<>();
/** * Constructs a new set containing the elements in the specified * collection, with default load factor and an initial * capacity sufficient to contain the elements in the specified collection. * * @param c Collection to add. */ public GridConcurrentWeakHashSet(Collection<E> c) { this(c.size()); addAll(c); }
/** {@inheritDoc} */ @Override public boolean addAll(@Nullable Collection<? extends E> c) { boolean res = false; if (!F.isEmpty(c)) { assert c != null; for (E e : c) { res |= add(e); } } return res; }