Java Code Examples for java.util.concurrent.ConcurrentHashMap#searchValues()

The following examples show how to use java.util.concurrent.ConcurrentHashMap#searchValues() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From Java-Coding-Problems with MIT License 6 votes vote down vote up
public static void main(String[] args) {

        ConcurrentHashMap<Integer, String> map = new ConcurrentHashMap<>();
        map.put(1, "Tylor");
        map.put(2, "Jenny");
        map.put(3, "Tymmy");
        map.put(4, "Anna");
        map.put(5, "Tysha");
        map.put(6, "Maria");

        System.out.println("Map: \n" + map);

        Integer key = map.search(2, (k, v) -> v.length() < 5 ? k : null);
        System.out.println("\nFind key via search(): " + key);

        Map.Entry<Integer, String> entry
                = map.searchEntries(2, (e) -> e.getValue().startsWith("A") ? e : null);
        System.out.println("\nFind entry via searchEntries(): " + entry);

        Integer keyFound = map.searchKeys(2, (k) -> k > 4 ? k : null);
        System.out.println("\nFind key via searchKeys(): " + keyFound);
        
        String valueFound = map.searchValues(2, (v) -> v.startsWith("M") ? v : null);
        System.out.println("\nFind value via searchValues(): " + valueFound);
    }
 
Example 2
Source File: ProgMainExecServConcurrentHashMap09.java    From javase with MIT License 5 votes vote down vote up
private static void testSearch() {
    ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
    map.putIfAbsent("foo", "bar");
    map.putIfAbsent("han", "solo");
    map.putIfAbsent("r2", "d2");
    map.putIfAbsent("c3", "p0");

    System.out.println("\nsearch()\n");

    String result1 = map.search(1, (key, value) -> {
        System.out.println(Thread.currentThread().getName());
        if (key.equals("foo") && value.equals("bar")) {
            return "foobar";
        }
        return null;
    });

    System.out.println(result1);

    System.out.println("\nsearchValues()\n");

    String result2 = map.searchValues(1, value -> {
        System.out.println(Thread.currentThread().getName());
        if (value.length() > 3) {
            return value;
        }
        return null;
    });

    System.out.println(result2);
}
 
Example 3
Source File: ConcurrentHashMap1.java    From javacore with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private static void testSearch() {
    ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
    map.putIfAbsent("foo", "bar");
    map.putIfAbsent("han", "solo");
    map.putIfAbsent("r2", "d2");
    map.putIfAbsent("c3", "p0");

    System.out.println("\nsearch()\n");

    String result1 = map.search(1, (key, value) -> {
        System.out.println(Thread.currentThread().getName());
        if ("foo".equals(key) && "bar".equals(value)) {
            return "foobar";
        }
        return null;
    });

    System.out.println(result1);

    System.out.println("\nsearchValues()\n");

    String result2 = map.searchValues(1, value -> {
        System.out.println(Thread.currentThread().getName());
        if (value.length() > 3) {
            return value;
        }
        return null;
    });

    System.out.println(result2);
}
 
Example 4
Source File: ConcurrentHashMap1.java    From java8-tutorial with MIT License 5 votes vote down vote up
private static void testSearch() {
    ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
    map.putIfAbsent("foo", "bar");
    map.putIfAbsent("han", "solo");
    map.putIfAbsent("r2", "d2");
    map.putIfAbsent("c3", "p0");

    System.out.println("\nsearch()\n");

    String result1 = map.search(1, (key, value) -> {
        System.out.println(Thread.currentThread().getName());
        if (key.equals("foo") && value.equals("bar")) {
            return "foobar";
        }
        return null;
    });

    System.out.println(result1);

    System.out.println("\nsearchValues()\n");

    String result2 = map.searchValues(1, value -> {
        System.out.println(Thread.currentThread().getName());
        if (value.length() > 3) {
            return value;
        }
        return null;
    });

    System.out.println(result2);
}