Example usage for java.util.concurrent ConcurrentHashMap search

List of usage examples for java.util.concurrent ConcurrentHashMap search

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap search.

Prototype

public <U> U search(long parallelismThreshold, BiFunction<? super K, ? super V, ? extends U> searchFunction) 

Source Link

Document

Returns a non-null result from applying the given search function on each (key, value), or null if none.

Usage

From source file:Main.java

public static void main(final String[] args) {
    ConcurrentHashMap<Integer, UUID> concurrentHashMap = new ConcurrentHashMap<>();

    for (int i = 0; i < 100; i++) {
        concurrentHashMap.put(i, UUID.randomUUID());
    }//w ww  . j a va 2  s.  c  o  m

    int threshold = 1;

    concurrentHashMap.forEachValue(threshold, System.out::println);

    concurrentHashMap.forEach((id, uuid) -> {
        if (id % 10 == 0) {
            System.out.println(String.format("%s: %s", id, uuid));
        }
    });

    String searchResult = concurrentHashMap.search(threshold, (id, uuid) -> {
        if (String.valueOf(uuid).contains(String.valueOf(id))) {
            return new String(id + ":" + uuid);
        }
        return null;
    });

    System.out.println(searchResult);
}