本文整理汇总了Java中org.apache.flink.api.common.functions.ReduceFunction.reduce方法的典型用法代码示例。如果您正苦于以下问题:Java ReduceFunction.reduce方法的具体用法?Java ReduceFunction.reduce怎么用?Java ReduceFunction.reduce使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.common.functions.ReduceFunction
的用法示例。
在下文中一共展示了ReduceFunction.reduce方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: putOrAggregate
import org.apache.flink.api.common.functions.ReduceFunction; //导入方法依赖的package包/类
/**
* Inserts or aggregates a value into the hash map. If the hash map does not yet contain the key,
* this method inserts the value. If the table already contains the key (and a value) this
* method will use the given ReduceFunction function to combine the existing value and the
* given value to a new value, and store that value for the key.
*
* @param key The key to map the value.
* @param value The new value to insert, or aggregate with the existing value.
* @param aggregator The aggregator to use if a value is already contained.
*
* @return The value in the map after this operation: Either the given value, or the aggregated value.
*
* @throws java.lang.NullPointerException Thrown, if the key is null.
* @throws Exception The method forwards exceptions from the aggregation function.
*/
public final V putOrAggregate(K key, V value, ReduceFunction<V> aggregator) throws Exception {
final int hash = hash(key);
final int slot = indexOf(hash);
// search the chain from the slot
for (Entry<K, V> entry = table[slot]; entry != null; entry = entry.next) {
if (entry.hashCode == hash && entry.key.equals(key)) {
// found match
entry.value = aggregator.reduce(entry.value, value);
return entry.value;
}
}
// no match, insert a new value
insertNewEntry(hash, key, value, slot);
// return the original value
return value;
}