@Override public boolean removeAll(Collection<?> collection) { assertTrue(Thread.holdsLock(mutex)); return delegate.removeAll(collection); }
@Test(dataProvider = "populated") public void removeAll_withPopulated(Queue<Integer> queue) { Integer first = queue.peek(); assertThat(queue.removeAll(ImmutableList.of(first)), is(true)); assertThat(queue, hasSize(POPULATED_SIZE - 1)); assertThat(queue.contains(first), is(false)); }
@Test(dataProvider = "empty") public void removeAll_withEmpty(Queue<Integer> queue) { assertThat(queue.removeAll(ImmutableList.of()), is(false)); assertThat(queue, is(deeplyEmpty())); }
@Test(dataProvider = "populated") public void removeAll_toEmpty(Queue<Integer> queue) { assertThat(queue.removeAll(ImmutableList.copyOf(queue)), is(true)); assertThat(queue, is(deeplyEmpty())); }
public void testHoldsLockOnAllOperations() { create().element(); create().offer("foo"); create().peek(); create().poll(); create().remove(); create().add("foo"); create().addAll(ImmutableList.of("foo")); create().clear(); create().contains("foo"); create().containsAll(ImmutableList.of("foo")); create().equals(new ArrayDeque<>(ImmutableList.of("foo"))); create().hashCode(); create().isEmpty(); create().iterator(); create().remove("foo"); create().removeAll(ImmutableList.of("foo")); create().retainAll(ImmutableList.of("foo")); create().size(); create().toArray(); create().toArray(new String[] {"foo"}); } }
@Override public boolean removeAll(final Collection c) { return queue.removeAll(c); }
@Test public void zeroQueueOperations() { Queue<Integer> q = Queues.<Integer>empty().get(); List<Integer> vals = Arrays.asList(1, 2, 3); assertThat(q.add(1)).as("add").isFalse(); assertThat(q.addAll(vals)).as("addAll").isFalse(); assertThat(q.offer(1)).as("offer").isFalse(); assertThat(q.peek()).as("peek").isNull(); assertThat(q.poll()).as("poll").isNull(); assertThat(q.contains(1)).as("contains").isFalse(); assertThat(q.iterator()).as("iterator").isEmpty(); assertThatExceptionOfType(NoSuchElementException.class) .as("element") .isThrownBy(q::element); assertThatExceptionOfType(NoSuchElementException.class) .as("remove") .isThrownBy(q::remove); assertThat(q.remove(1)).as("remove").isFalse(); assertThat(q.containsAll(vals)).as("containsAll").isFalse(); assertThat(q.retainAll(vals)).as("retainAll").isFalse(); assertThat(q.removeAll(vals)).as("removeAll").isFalse(); assertThatCode(q::clear).as("clear").doesNotThrowAnyException(); assertThat(q) .hasSize(0) .isEmpty(); assertThat(q.toArray()).as("toArray").isEmpty(); assertThat(q.toArray(new Integer[0])).as("toArray(empty)").isEmpty(); Integer[] array = new Integer[]{-1, -2, -3}; assertThat(q.toArray(array)).as("toArray(pre-filled)").containsExactly(null, -2, -3); }
/** * 求俩个集合的差集 * * @param queue1 队列 * @param queue2 队列 * @param <T> 泛型 * @return 差集 */ public static <T> Queue<T> subtract(Queue<T> queue1, Queue<T> queue2) { Queue<T> queue = new LinkedList<>(); if (CheckUtil.valid(queue1)) { queue.addAll(queue1); queue.removeAll(queue2); } return queue; }
@Test(expected = UnsupportedOperationException.class) public void removeView(){ Queue<Integer> list = of(1,2,3).queueView(); assertThat(list.remove(1),equalTo(false)); assertThat(list.remove((Object)1),equalTo(false)); assertThat(list.removeAll(Arrays.asList(1)),equalTo(false)); } @Test(expected = UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class) public void addAllView(){ Queue<Integer> list = of(1,2,3).queueView(); assertThat(list.addAll(Arrays.asList(1)),equalTo(false)); assertThat(list.contains(2),equalTo(true)); assertThat(list.containsAll(Arrays.asList(2,3)),equalTo(true)); assertThat(list.containsAll(Arrays.asList(2,3,4)),equalTo(false)); assertThat(list.remove(1),equalTo(false)); assertThat(list.remove((Object)1),equalTo(false)); assertThat(list.removeAll(Arrays.asList(1)),equalTo(false)); }
@Test(expected = UnsupportedOperationException.class) public void removeAllView(){ Queue<Integer> list = of(1,2,3).queueView(); assertThat(list.removeAll(Arrays.asList(1)),equalTo(false)); }
/** * {@inheritDoc} */ @Override public synchronized boolean removeAll(Collection<?> c) { return queue.removeAll(c); }
/** * {@inheritDoc} */ @Override public synchronized boolean removeAll(Collection<?> c) { return queue.removeAll(c); }
@Override public boolean removeAll(Collection<?> collection) { boolean result = messages.removeAll(collection); this.storeMessageQueue(); return result; }
void clearCompletedImports() { List<ImportContext> completed = collect(new ImportCollector() { @Override protected boolean capture(ImportContext context) { return context.getState() == ImportContext.State.COMPLETE; } }); imports.removeAll(completed); }
void clearCompletedImports() { List<ImportContext> completed = collect( new ImportCollector() { @Override protected boolean capture(ImportContext context) { return context.getState() == ImportContext.State.COMPLETE; } }); imports.removeAll(completed); }
@Override public boolean removeAll(Collection<?> collection) { boolean result = messages.removeAll(collection); this.storeMessageQueue(); return result; }
public synchronized void cancelAll() { Collection<Message> messagesToCancel = new LinkedList<Message>(); for (Message elem : messagesToBeSent) { if (elem.getType() == Message.PIECE) { messagesToCancel.add(elem); } } messagesToBeSent.removeAll(messagesToCancel); }
@Override public boolean removeAll(Collection<?> collection) { assertTrue(Thread.holdsLock(mutex)); return delegate.removeAll(collection); }
void removeDrawables(final Collection<IDrawable> c) { acquireLock(); try { contents.removeAll(c); isDirty = true; } finally { releaseLock(); } }