Search in sources :

Example 76 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testMerge1.

/**
     * merge adds when the given key is not present
     */
public void testMerge1() {
    ConcurrentMap map = map5();
    assertEquals("Y", map.merge(six, "Y", (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestSuite(junit.framework.TestSuite) DISTINCT(java.util.Spliterator.DISTINCT) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 77 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testCompute4.

/**
     * compute removes when the given key is present and function returns null
     */
public void testCompute4() {
    ConcurrentMap map = map5();
    map.compute(one, (x, y) -> null);
    assertFalse(map.containsKey(one));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 78 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testMerge2.

/**
     * merge replaces when the given key is present
     */
public void testMerge2() {
    ConcurrentMap map = map5();
    assertEquals("Z", map.merge(one, "Y", (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestSuite(junit.framework.TestSuite) DISTINCT(java.util.Spliterator.DISTINCT) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 79 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method map5.

/**
     * Returns a new map from Integers 1-5 to Strings "A"-"E".
     */
private static ConcurrentMap map5() {
    ConcurrentMap map = map();
    assertTrue(map.isEmpty());
    map.put(one, "A");
    map.put(two, "B");
    map.put(three, "C");
    map.put(four, "D");
    map.put(five, "E");
    assertFalse(map.isEmpty());
    assertEquals(5, map.size());
    return map;
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 80 with ConcurrentMap

use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.

the class ConcurrentHashMap8Test method testComputeIfPresent2.

/**
     * computeIfPresent adds when the given key is not present
     */
public void testComputeIfPresent2() {
    ConcurrentMap map = map5();
    assertEquals("Z", map.computeIfPresent(one, (x, y) -> "Z"));
}
Also used : NONNULL(java.util.Spliterator.NONNULL) LongAdder(java.util.concurrent.atomic.LongAdder) Arrays(java.util.Arrays) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Test(junit.framework.Test) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) ConcurrentMap(java.util.concurrent.ConcurrentMap) TestSuite(junit.framework.TestSuite) DISTINCT(java.util.Spliterator.DISTINCT) NoSuchElementException(java.util.NoSuchElementException) CONCURRENT(java.util.Spliterator.CONCURRENT) Collections(java.util.Collections) Spliterator(java.util.Spliterator) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ConcurrentMap (java.util.concurrent.ConcurrentMap)218 Map (java.util.Map)53 Test (org.junit.Test)47 HashMap (java.util.HashMap)31 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)28 ArrayList (java.util.ArrayList)26 Set (java.util.Set)20 URL (com.alibaba.dubbo.common.URL)17 Iterator (java.util.Iterator)11 IOException (java.io.IOException)10 Collection (java.util.Collection)10 Arrays (java.util.Arrays)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)7 List (java.util.List)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 LongAdder (java.util.concurrent.atomic.LongAdder)6 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)5