@Test void removeAll() { BlockingQueue<String> queue = new MapBasedLinkedBlockingQueue(this.map); assertEquals(4, queue.size()); queue.add("Bar"); assertEquals(5, queue.size()); assertEquals(5, this.map.size()); assertTrue(queue.removeAll(Arrays.asList("Bar", "buz"))); assertEquals(2, queue.size()); assertEquals(2, this.map.size()); assertEquals("Baz", queue.poll()); assertEquals("Foo", queue.poll()); assertTrue(queue.isEmpty()); assertTrue(this.map.isEmpty()); queue.add("Foo"); queue.add("Bar"); assertFalse(queue.removeAll(Collections.singleton("Toto"))); assertEquals(2, queue.size()); assertEquals(2, this.map.size()); }
@Override public boolean removeAll(Collection<?> collection) { boolean result = false; Iterator<T> iterator = this.iterator(); while (iterator.hasNext()) { T element = iterator.next(); if (collection.contains(element)) { iterator.remove(); result = true; } } return result; }
MapBasedLinkedBlockingQueue implements BlockingQueue<T> { @Override public boolean removeAll(Collection<?> collection) { boolean result = false; Iterator<T> iterator = this.iterator(); while (iterator.hasNext()) { T element = iterator.next(); if (collection.contains(element)) { iterator.remove(); result = true; } } return result; } }
MapBasedLinkedBlockingQueue implements BlockingQueue<T> { @Override public boolean removeAll(Collection<?> collection) { boolean result = false; Iterator<T> iterator = this.iterator(); while (iterator.hasNext()) { T element = iterator.next(); if (collection.contains(element)) { iterator.remove(); result = true; } } return result; } MapBasedLinkedBlockingQueue(ConcurrentMap<Long, T> internalMap); }
MapBasedLinkedBlockingQueue implements BlockingQueue<T> { @Override public boolean removeAll(Collection<?> collection) { boolean result = false; Iterator<T> iterator = this.iterator(); while (iterator.hasNext()) { T element = iterator.next(); if (collection.contains(element)) { iterator.remove(); result = true; } } return result; } MapBasedLinkedBlockingQueue(ConcurrentMap<Long, T> internalMap); @Override void put(T t); @Override boolean offer(T t, long l, TimeUnit timeUnit); @Override boolean offer(T t); @Override T take(); @Override T poll(long l, TimeUnit timeUnit); @Override int remainingCapacity(); @Override T poll(); @Override T element(); @Override T peek(); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> collection); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<T> iterator(); @Override Object[] toArray(); @Override T1[] toArray(T1[] t1s); @Override void clear(); @Override int drainTo(Collection<? super T> collection); @Override int drainTo(Collection<? super T> collection, int i); @Override boolean add(T t); @Override T remove(); @Override boolean addAll(Collection<? extends T> collection); @Override boolean removeAll(Collection<?> collection); @Override boolean retainAll(Collection<?> collection); }
MapBasedLinkedBlockingQueue implements BlockingQueue<T> { @Override public boolean removeAll(Collection<?> collection) { boolean result = false; Iterator<T> iterator = this.iterator(); while (iterator.hasNext()) { T element = iterator.next(); if (collection.contains(element)) { iterator.remove(); result = true; } } return result; } MapBasedLinkedBlockingQueue(ConcurrentMap<Long, T> internalMap); @Override void put(T t); @Override boolean offer(T t, long l, TimeUnit timeUnit); @Override boolean offer(T t); @Override T take(); @Override T poll(long l, TimeUnit timeUnit); @Override int remainingCapacity(); @Override T poll(); @Override T element(); @Override T peek(); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> collection); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<T> iterator(); @Override Object[] toArray(); @Override T1[] toArray(T1[] t1s); @Override void clear(); @Override int drainTo(Collection<? super T> collection); @Override int drainTo(Collection<? super T> collection, int i); @Override boolean add(T t); @Override T remove(); @Override boolean addAll(Collection<? extends T> collection); @Override boolean removeAll(Collection<?> collection); @Override boolean retainAll(Collection<?> collection);  }