private boolean shouldEnqueue( boolean force, T item ) { // Add index if not in queue if ( queue.contains( item ) ) { return false; } // and either adding all if ( force ) { return true; } // or otherwise only if seen enough updates (as determined by updatePredicate) return enqueueablePredicate.test( item ); }
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 contains(Object object) { return delegate().contains(checkNotNull(object)); }
/** * Drains the recency queue, updating eviction metadata that the entries therein were read in * the specified relative order. This currently amounts to adding them to relevant eviction * lists (accounting for the fact that they could have been removed from the map since being * added to the recency queue). */ @GuardedBy("this") void drainRecencyQueue() { ReferenceEntry<K, V> e; while ((e = recencyQueue.poll()) != null) { // An entry may be in the recency queue despite it being removed from // the map . This can occur when the entry was concurrently read while a // writer is removing it from the segment or after a clear has removed // all of the segment's entries. if (accessQueue.contains(e)) { accessQueue.add(e); } } }
@Override public boolean contains(Object object) { return delegate().contains(checkNotNull(object)); }
@Override public boolean contains(Object object) { assertTrue(Thread.holdsLock(mutex)); return delegate.contains(object); }
@Override public boolean contains(Object collection, Object entity) { return ( (Queue) collection ).contains( entity ); }
@Override public boolean contains(Object object) { return delegate().contains(checkNotNull(object)); }
@Test(dataProvider = "empty") public void contains_withNull(Queue<?> queue) { assertThat(queue.contains(null), is(false)); }
@Test(dataProvider = "populated") public void contains_whenNotFound(Queue<Integer> queue) { assertThat(queue.contains(-1), is(false)); }
@Test(dataProvider = "populated") public void contains_whenFound(Queue<Integer> queue) { assertThat(queue.contains(Iterables.get(queue, POPULATED_SIZE / 2)), is(true)); }
@Test(dataProvider = "populated") public void poll_whenPopulated(Queue<Integer> queue) { Integer first = queue.peek(); assertThat(queue.poll(), is(first)); assertThat(queue, hasSize(POPULATED_SIZE - 1)); assertThat(queue.contains(first), is(false)); }
@Test(dataProvider = "populated") public void removeElement_whenFound(Queue<Integer> queue) { Integer first = queue.peek(); assertThat(queue.remove(first), is(true)); assertThat(queue, hasSize(POPULATED_SIZE - 1)); assertThat(queue.contains(first), is(false)); }
@Test(dataProvider = "populated") public void remove_whenPopulated(Queue<Integer> queue) { Integer first = queue.peek(); assertThat(queue.remove(), is(first)); assertThat(queue, hasSize(POPULATED_SIZE - 1)); assertThat(queue.contains(first), is(false)); }
@Test(dataProvider = "populated") public void remove_toEmpty(Queue<Integer> queue) { while (!queue.isEmpty()) { Integer value = queue.remove(); assertThat(queue.contains(value), is(false)); } assertThat(queue, is(deeplyEmpty())); }
@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 = "populated") public void retainAll_withPopulated(Queue<Integer> queue) { Integer first = queue.peek(); assertThat(queue.retainAll(ImmutableList.of(first)), is(true)); assertThat(queue, hasSize(1)); assertThat(queue.contains(first), is(true)); }
@Test(dataProvider = "populated") public void poll_toEmpty(Queue<Integer> queue) { Integer value; while ((value = queue.poll()) != null) { assertThat(queue.contains(value), is(false)); } assertThat(queue, is(deeplyEmpty())); }
@Test(dataProvider = "populated") public void removeElement_toEmpty(Queue<Integer> queue) { while (!queue.isEmpty()) { Integer value = queue.peek(); assertThat(queue.remove(value), is(true)); assertThat(queue.contains(value), is(false)); } assertThat(queue, is(deeplyEmpty())); }
public void testRemoveEntry() { LocalCache<Object, Object> map = makeLocalCache( createCacheBuilder() .concurrencyLevel(1) .initialCapacity(1) .maximumSize(SMALL_MAX_SIZE) .expireAfterWrite(99999, SECONDS) .removalListener(countingRemovalListener())); Segment<Object, Object> segment = map.segments[0]; AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table; assertEquals(1, table.length()); Object key = new Object(); Object value = new Object(); int hash = map.hash(key); DummyEntry<Object, Object> entry = createDummyEntry(key, hash, value, null); // remove absent assertFalse(segment.removeEntry(entry, hash, RemovalCause.COLLECTED)); // remove live segment.recordWrite(entry, 1, map.ticker.read()); table.set(0, entry); segment.count = 1; assertTrue(segment.removeEntry(entry, hash, RemovalCause.COLLECTED)); assertNotificationEnqueued(map, key, value, hash); assertTrue(map.removalNotificationQueue.isEmpty()); assertFalse(segment.accessQueue.contains(entry)); assertFalse(segment.writeQueue.contains(entry)); assertEquals(0, segment.count); assertNull(table.get(0)); }