public void add(Number n) { sum.add(n); }
public void add(double d) { sum.add(d); count.add(1); }
/** * Adds the value for each key. * @param tuple * @param map */ public void addTuple(Map<K, V> tuple, Map<K, MutableDouble> map) { for (Map.Entry<K, V> e: tuple.entrySet()) { if (!doprocessKey(e.getKey()) || (e.getValue() == null)) { continue; } MutableDouble val = map.get(e.getKey()); if (val == null) { val = new MutableDouble(0.0); map.put(cloneKey(e.getKey()), val); } val.add(e.getValue().doubleValue()); } }
@Override public void process(String timeBucket, String key, String field, Number value) { String finalKey = timeBucket + "|" + key; Map<String, Number> m = dataMap.get(finalKey); if (value == null) { return; } if (m == null) { m = new HashMap<String, Number>(); m.put(field, new MutableDouble(value)); dataMap.put(finalKey, m); } else { Number n = m.get(field); if (n == null) { m.put(field, new MutableDouble(value)); } else { ((MutableDouble)n).add(value); } } }
currentPatternMap.put(builder.toString(), currentDimensionKeyValPair); } else { currentDimensionKeyValPair.getKey().add(tupleValue.get(dimensionKeyVal)); currentDimensionKeyValPair.setValue(currentDimensionKeyValPair.getValue() + 1);
currentDimensionKeyValPair.getKey().add(0 - tupleValue.get(dimensionKeyVal).doubleValue()); currentDimensionKeyValPair.setValue(currentDimensionKeyValPair.getValue() - 1); if (currentDimensionKeyValPair.getKey().doubleValue() == 0.0) {
@Override public void process(Map<String, DimensionObject<String>> tuple) { for (Map.Entry<String, DimensionObject<String>> e : tuple.entrySet()) { Map<String, MutableDouble> obj = dataMap.get(e.getKey()); DimensionObject<String> eObj = e.getValue(); if (obj == null) { obj = new HashMap<String, MutableDouble>(); obj.put(eObj.getVal(), new MutableDouble(eObj.getCount())); dataMap.put(e.getKey(), obj); } else { MutableDouble n = obj.get(eObj.getVal()); if (n == null) { obj.put(eObj.getVal(), new MutableDouble(eObj.getCount())); } else { n.add(eObj.getCount()); } } } } };
map.put(field, convertToNumber(entry1.getValue())); } else if (oldVal instanceof MutableDouble) { ((MutableDouble)oldVal).add(convertToNumber(entry1.getValue())); } else if (oldVal instanceof MutableLong) { ((MutableLong)oldVal).add(convertToNumber(entry1.getValue())); } else { if (oldVal instanceof MutableDouble) { ((MutableDouble)oldVal).add(convertToNumber(value)); } else if (oldVal instanceof MutableLong) { ((MutableLong)oldVal).add(convertToNumber(value));
val = new MutableDouble(e.getValue().doubleValue()); } else { val.add(e.getValue().doubleValue());
val = new MutableDouble(e.getValue().doubleValue()); } else { val.add(e.getValue().doubleValue());
val.increment(); } else { val.add(value.doubleValue());
/** * Adds the value for each key. * * @param tuple * @param map */ public void addTuple(KeyValPair<K, V> tuple, Map<K, MutableDouble> map) { K key = tuple.getKey(); if (!doprocessKey(key) || (tuple.getValue() == null)) { return; } MutableDouble val = map.get(key); if (val == null) { val = new MutableDouble(0.0); map.put(cloneKey(key), val); } val.add(tuple.getValue().doubleValue()); }
val.increment(); } else { val.add(value.doubleValue());
/** * For each tuple (a key value pair) Adds the values for each key. */ @Override public void process(KeyValPair<K, V> tuple) { K key = tuple.getKey(); if (!doprocessKey(key)) { return; } SumEntry val = sums.get(key); if (val == null) { val = new SumEntry(new MutableDouble(tuple.getValue().doubleValue()), true); } else { val.sum.add(tuple.getValue().doubleValue()); val.changed = true; } sums.put(cloneKey(key), val); }
/** * Adds the values for each key, counts the number of occurrences of each * key and computes the average. */ @Override public void process(KeyValPair<K, ? extends Number> tuple) { K key = tuple.getKey(); if (!doprocessKey(key)) { return; } MutableDouble val = sums.get(key); if (val == null) { val = new MutableDouble(tuple.getValue().doubleValue()); } else { val.add(tuple.getValue().doubleValue()); } sums.put(cloneKey(key), val); MutableLong count = counts.get(key); if (count == null) { count = new MutableLong(0); counts.put(cloneKey(key), count); } count.increment(); } };
/** * Used to accumulate store metrics across multiple regions in a region * server. These metrics are not "persistent", i.e. we keep overriding them * on every update instead of incrementing, so we need to accumulate them in * a temporary map before pushing them to the global metric collection. * @param tmpMap a temporary map for accumulating store metrics * @param storeMetricType the store metric type to increment * @param val the value to add to the metric */ public void accumulateStoreMetric(final Map<String, MutableDouble> tmpMap, StoreMetricType storeMetricType, double val) { final String key = getStoreMetricName(storeMetricType); if (tmpMap.get(key) == null) { tmpMap.put(key, new MutableDouble(val)); } else { tmpMap.get(key).add(val); } if (this == ALL_SCHEMA_METRICS) { // also compute the max value across all Stores on this server final String maxKey = getStoreMetricNameMax(storeMetricType); MutableDouble cur = tmpMap.get(maxKey); if (cur == null) { tmpMap.put(maxKey, new MutableDouble(val)); } else if (cur.doubleValue() < val) { cur.setValue(val); } } else { ALL_SCHEMA_METRICS.accumulateStoreMetric(tmpMap, storeMetricType, val); } }
/** * Processes all the {@link SqlStatementData}s in the given invocations creating the list of the * existing statement and calculating the total duration of the statements. * * @param invocationSequenceDataList * Input as list of invocations * @param sqlStatementDataList * List where results will be stored. Needed because of reflection. * @param totalDuration * {@link MutableDouble} where total duration will be stored. */ public static void collectSqlsInInvocations(List<InvocationSequenceData> invocationSequenceDataList, List<SqlStatementData> sqlStatementDataList, MutableDouble totalDuration) { for (InvocationSequenceData invocationSequenceData : invocationSequenceDataList) { if (null != invocationSequenceData.getSqlStatementData()) { sqlStatementDataList.add(invocationSequenceData.getSqlStatementData()); totalDuration.add(invocationSequenceData.getSqlStatementData().getDuration()); } if (CollectionUtils.isNotEmpty(invocationSequenceDataList)) { collectSqlsInInvocations(invocationSequenceData.getNestedSequences(), sqlStatementDataList, totalDuration); } } }
private void processTuple(MerchantTransaction tuple) { emitBankIdNumTuple(tuple, binCountOutputPort); emitMerchantKeyTuple(tuple, txOutputPort); emitCreditCardKeyTuple(tuple, ccAlertOutputPort); totalTxns.increment(); txnsInLastSecond.increment(); amtInLastSecond.add(tuple.amount); }