下面列出了com.google.common.util.concurrent.AtomicLongMap#addAndGet ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testIncrement() throws Exception {
AtomicLongMap<String> cache = AtomicLongMap.create();
cache.addAndGet("a", 1L);
cache.addAndGet("a", 2L);
cache.addAndGet("b", 5L);
Map<String, Long> remove = AtomicLongMapUtils.remove(cache);
Assert.assertEquals((long) remove.get("a"), 3L);
Assert.assertEquals((long) remove.get("b"), 5L);
cache.addAndGet("a", 1L);
Map<String, Long> remove2 = AtomicLongMapUtils.remove(cache);
Assert.assertEquals((long) remove2.get("a"), 1L);
}
private void dumpAllState(DumpData dumpData) {
AtomicLongMap<Integer> allStateMap = AtomicLongMap.create();
List<Map<Integer, Long>> allRecord = ImmutableList.of(dumpData.getBlockedTimes(), dumpData.getRunnableCpuTimes(),
dumpData.getTimedWaitingTimes(), dumpData.getWaitingTimes());
for (Map<Integer, Long> cpuTime : allRecord) {
for (Map.Entry<Integer, Long> entry : cpuTime.entrySet()) {
allStateMap.addAndGet(entry.getKey(), entry.getValue());
}
}
doDump(allStateMap.asMap(), Manager.getAllStatePath(), false);
doDump(allStateMap.asMap(), Manager.getFilterAllStatePath(), true);
}
private AtomicLongMap<PartitionRefiner> createSelectivityEstimation(IEvidenceSet sampleEvidence,
Set<PredicatePair> predicatePairs) {
AtomicLongMap<PartitionRefiner> selectivityCount = AtomicLongMap.create();
for (PredicateBitSet ps : sampleEvidence) {
int count = (int) sampleEvidence.getCount(ps);
ps.forEach(p -> {
selectivityCount.addAndGet(p, count);
});
for (PredicatePair pair : predicatePairs)
if (pair.bothContainedIn(ps)) {
selectivityCount.addAndGet(pair, sampleEvidence.getCount(ps));
}
}
return selectivityCount;
}
@Test
public void testIntegerMax() throws Exception {
AtomicLongMap<String> cache = AtomicLongMap.create();
cache.addAndGet("a", 1L);
cache.addAndGet("a", 2L);
cache.addAndGet("b", 5L);
}
@Test
public void testIntegerMin() throws Exception {
AtomicLongMap<String> cache = AtomicLongMap.create();
cache.addAndGet("a", 1L);
cache.addAndGet("a", 2L);
cache.addAndGet("b", 5L);
}