/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.datatorrent.lib.math;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.mutable.MutableDouble;
import org.apache.commons.lang.mutable.MutableInt;
import com.datatorrent.api.DefaultInputPort;
import com.datatorrent.api.DefaultOutputPort;
import com.datatorrent.api.annotation.OutputPortFieldAnnotation;
import com.datatorrent.lib.util.BaseNumberKeyValueOperator;
import com.datatorrent.lib.util.UnifierHashMapInteger;
import com.datatorrent.lib.util.UnifierHashMapSumKeys;
/**
* Emits the sum and count of values for each key at the end of window.
*
* Application accumulate sum across streaming window by setting cumulative flag
* to true.
* This is an end of window operator
*
* StateFull : Yes, Sum is computed over application window and streaming
* window.
* Partitions : Yes, Sum is unified at output port.
*
* Ports:
* data: expects Map<K,V extends Number>
* sum: emits HashMap<K,V>
* count: emits HashMap<K,Integer>
*
* Properties:
* inverse: if set to true the key in the filter will block tuple
* filterBy: List of keys to filter on
* cumulative: boolean flag, if set the sum is not cleared at the end of
* window,
* hence generating cumulative sum across streaming windows. Default is false.
*
* @displayName Sum Count Map
* @category Math
* @tags number, sum, counting, map
* @since 0.3.3
*/
public class SumCountMap extends
BaseNumberKeyValueOperator
{
/**
* Key/double sum map.
*/
protected HashMap sums = new HashMap();
/**
* Key/integer sum map.
*/
protected HashMap counts = new HashMap();
/**
* Cumulative sum flag.
*/
protected boolean cumulative = false;
/**
* Input port that takes a map. It adds the values for each key and counts the number of occurrences for each key.
*/
public final transient DefaultInputPort