Example usage for com.google.common.util.concurrent AtomicLongMap addAndGet

List of usage examples for com.google.common.util.concurrent AtomicLongMap addAndGet

Introduction

In this page you can find the example usage for com.google.common.util.concurrent AtomicLongMap addAndGet.

Prototype

public long addAndGet(K key, long delta) 

Source Link

Document

Adds delta to the value currently associated with key , and returns the new value.

Usage

From source file:com.cloudera.oryx.app.mllib.rdf.RDFUpdate.java

private static AtomicLongMap<Integer> merge(AtomicLongMap<Integer> a, AtomicLongMap<Integer> b) {
    for (Map.Entry<Integer, Long> e : b.asMap().entrySet()) {
        a.addAndGet(e.getKey(), e.getValue());
    }/* w ww . j  a v a 2  s. c  om*/
    return a;
}

From source file:org.mondemand.Client.java

/**
 * Given context&Stats map, increment according to context and key/value
 * @param context context//from ww w.ja v  a 2s .co m
 * @param keyType key
 * @param value value
 * @throws MondemandException
 */
public void increment(ContextList context, String keyType, long value) throws MondemandException {
    if (!isKeyValid(keyType)) {
        throw new MondemandException("key is invalid: " + keyType);
    }

    // Note: add could be lost due to a race condition but no
    //       synchronization is required.
    AtomicLongMap<String> stats = contextStats.get(context);
    if (stats == null) {
        AtomicLongMap<String> newStats = AtomicLongMap.create();
        stats = contextStats.putIfAbsent(context, newStats);
        if (stats == null) {
            stats = newStats;
        }
    }
    stats.addAndGet(keyType, value);
}