本文整理汇总了Java中com.google.common.util.concurrent.AtomicLongMap类的典型用法代码示例。如果您正苦于以下问题:Java AtomicLongMap类的具体用法?Java AtomicLongMap怎么用?Java AtomicLongMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AtomicLongMap类属于com.google.common.util.concurrent包,在下文中一共展示了AtomicLongMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
public static EurostagFakeNodes build(Network network, EurostagEchExportConfig config) {
Objects.requireNonNull(network);
Objects.requireNonNull(config);
BiMap<String, String> fakeNodesMap = HashBiMap.create(new HashMap<>());
AtomicLongMap<String> countUsesMap = AtomicLongMap.create();
//adds 2 default fake nodes
fakeNodesMap.put(EchUtil.FAKE_NODE_NAME1, EchUtil.FAKE_NODE_NAME1);
countUsesMap.getAndIncrement(EchUtil.FAKE_NODE_NAME1);
fakeNodesMap.put(EchUtil.FAKE_NODE_NAME2, EchUtil.FAKE_NODE_NAME2);
countUsesMap.getAndIncrement(EchUtil.FAKE_NODE_NAME2);
Identifiables.sort(network.getVoltageLevels()).stream().map(VoltageLevel::getId).forEach(vlId ->
fakeNodesMap.put(vlId, newEsgId(fakeNodesMap, vlId)));
return new EurostagFakeNodes(fakeNodesMap, countUsesMap, network);
}
示例2: end
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
@Override
public void end() {
for(Map.Entry<String, AtomicLongMap<String>> entry : aggregation.entrySet()) {
String fieldName = entry.getKey();
AtomicLongMap<String> fieldValue = entry.getValue();
for(Map.Entry<String,Long> fieldValueEntry : fieldValue.asMap().entrySet()) {
String value = fieldValueEntry.getKey();
Long count = fieldValueEntry.getValue();
Document document = new Document();
document.setField("value", value);
document.setField("count", count);
document.setField("type", fieldName);
super.document(document);
}
}
super.end();
}
示例3: testIncrement
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
@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);
}
示例4: testConsistentHash_probabilities
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
public void testConsistentHash_probabilities() {
AtomicLongMap<Integer> map = AtomicLongMap.create();
Random r = new Random(9);
for (int i = 0; i < ITERS; i++) {
countRemaps(r.nextLong(), map);
}
for (int shard = 2; shard <= MAX_SHARDS; shard++) {
// Rough: don't exceed 1.2x the expected number of remaps by more than 20
assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
}
}
示例5: countRemaps
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
private void countRemaps(long h, AtomicLongMap<Integer> map) {
int last = 0;
for (int shards = 2; shards <= MAX_SHARDS; shards++) {
int chosen = Hashing.consistentHash(h, shards);
if (chosen != last) {
map.incrementAndGet(shards);
last = chosen;
}
}
}
示例6: TermVectorsFilter
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
public TermVectorsFilter(Fields termVectorsByField, Fields topLevelFields, Set<String> selectedFields, @Nullable AggregatedDfs dfs) {
this.fields = termVectorsByField;
this.topLevelFields = topLevelFields;
this.selectedFields = selectedFields;
this.dfs = dfs;
this.scoreTerms = new HashMap<>();
this.sizes = AtomicLongMap.create();
this.similarity = new DefaultSimilarity();
}
示例7: PartitionMarkowData
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
PartitionMarkowData(List<Actor> actors) {
this.actors = ActorsSorter.topologicalOrder(actors);
successorsMap = new HashMap<>();
for (Actor actor : actors) {
successorsMap.put(actor, AtomicLongMap.create());
}
firings = AtomicLongMap.create();
lastFiredActor = null;
firstFiredActor = null;
}
示例8: Pcp
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
Pcp(String partition) {
this.partition = partition;
finishTime = 0;
pcpFirings = AtomicLongMap.create();
sumPcpWeightMap = new HashMap<>();
maxBlockedTokens = new HashMap<>();
maxBlockedMultiplication = new HashMap<>();
blockingInstances = new HashMap<>();
partitionsBlockingMap = new HashMap<>();
}
示例9: Pcp
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
private Pcp(Action action, double weight, double variance) {
pcpWeight = weight;
pcpVariance = variance;
pcpFirings = AtomicLongMap.create();
pcpFirings.incrementAndGet(action);
sumPcpWeightMap = new HashMap<>();
sumPcpWeightMap.put(action, weight);
sumPcpVarianceMap = new HashMap<>();
sumPcpVarianceMap.put(action, variance);
}
示例10: VectorClock
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
public VectorClock(Vector<Integer> ids) {
minClock = 0;
vecClock = AtomicLongMap.create();
for (Integer id : ids) {
vecClock.put(id, 0);
}
}
示例11: testConsistentHash_probabilities
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
public void testConsistentHash_probabilities() {
AtomicLongMap<Integer> map = AtomicLongMap.create();
Random r = new Random(9);
for (int i = 0; i < ITERS; i++) {
countRemaps(r.nextLong(), map);
}
for (int shard = 2; shard <= MAX_SHARDS; shard++) {
// Rough: don't exceed 1.2x the expected number of remaps by more than 20
assertTrue(map.get(shard) <= 1.2 * ITERS / shard + 20);
}
}
示例12: countRemaps
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
private void countRemaps(long h, AtomicLongMap<Integer> map) {
int last = 0;
for (int shards = 2; shards <= MAX_SHARDS; shards++) {
int chosen = Hashing.consistentHash(h, shards);
if (chosen != last) {
map.incrementAndGet(shards);
last = chosen;
}
}
}
示例13: remove
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
public static <T> Map<T, Long> remove(AtomicLongMap<T> atomicLongMap) {
final Map<T, Long> view = atomicLongMap.asMap();
// view.size() is not recommended, cache entry is striped and volatile field
final List<T> keySnapshot = keySnapshot(view);
return remove(atomicLongMap, keySnapshot);
}
示例14: testIntegerMax
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
@Test
public void testIntegerMax() throws Exception {
AtomicLongMap<String> cache = AtomicLongMap.create();
cache.addAndGet("a", 1L);
cache.addAndGet("a", 2L);
cache.addAndGet("b", 5L);
}
示例15: testIntegerMin
import com.google.common.util.concurrent.AtomicLongMap; //导入依赖的package包/类
@Test
public void testIntegerMin() throws Exception {
AtomicLongMap<String> cache = AtomicLongMap.create();
cache.addAndGet("a", 1L);
cache.addAndGet("a", 2L);
cache.addAndGet("b", 5L);
}