本文整理了Java中org.apache.flink.streaming.runtime.operators.windowing.KeyMap.putIfAbsent()
方法的一些代码示例,展示了KeyMap.putIfAbsent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyMap.putIfAbsent()
方法的具体详情如下:
包路径:org.apache.flink.streaming.runtime.operators.windowing.KeyMap
类名称:KeyMap
方法名:putIfAbsent
[英]Inserts a value for the given key, if no value is yet contained for that key. Otherwise, returns the value currently contained for the key.
The value that is inserted in case that the key is not contained, yet, is lazily created using the given factory.
[中]如果给定键尚未包含任何值,则为该键插入一个值。否则,返回键当前包含的值。
在尚未包含键的情况下插入的值是使用给定工厂延迟创建的。
代码示例来源:origin: apache/flink
@Test
public void testPutIfAbsentDuplicateKeysAndGrowth() {
try {
KeyMap<Integer, Integer> map = new KeyMap<>();
IntegerFactory factory = new IntegerFactory();
final int numElements = 1000000;
for (int i = 0; i < numElements; i++) {
int val = 2 * i + 1;
factory.set(val);
Integer put = map.putIfAbsent(i, factory);
assertEquals(val, put.intValue());
}
for (int i = 0; i < numElements; i += 3) {
factory.set(2 * i);
Integer put = map.putIfAbsent(i, factory);
assertEquals(2 * i + 1, put.intValue());
}
for (int i = 0; i < numElements; i++) {
assertEquals(2 * i + 1, map.get(i).intValue());
}
assertEquals(numElements, map.size());
assertEquals(numElements, map.traverseAndCountElements());
assertEquals(1 << 21, map.getCurrentTableCapacity());
assertTrue(map.getLongestChainLength() <= 7);
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
代码示例来源:origin: apache/flink
map.putIfAbsent(i, factory);
代码示例来源:origin: org.apache.flink/flink-streaming-java_2.10
@Override
public void addElementToLatestPane(Type element) throws Exception {
Key k = keySelector.getKey(element);
ArrayList<Type> elements = latestPane.putIfAbsent(k, listFactory);
elements.add(element);
}
内容来源于网络,如有侵权,请联系作者删除!