本文整理汇总了Java中org.apache.commons.lang.mutable.MutableDouble类的典型用法代码示例。如果您正苦于以下问题:Java MutableDouble类的具体用法?Java MutableDouble怎么用?Java MutableDouble使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MutableDouble类属于org.apache.commons.lang.mutable包,在下文中一共展示了MutableDouble类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accumulateStoreMetric
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
/**
* 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);
}
}
示例2: processTuple
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
private void processTuple(KeyValPair<MerchantKey, Long> tuple)
{
MerchantKey merchantKey = tuple.getKey();
MutableDouble lastSma = lastSMAMap.get(tuple.getKey());
long txValue = tuple.getValue();
if (lastSma != null && txValue > lastSma.doubleValue()) {
double lastSmaValue = lastSma.doubleValue();
double change = txValue - lastSmaValue;
if (change > threshold) { // generate an alert
AverageAlertData data = getOutputData(merchantKey, txValue, change, lastSmaValue);
alerts.add(data);
//if (userGenerated) { // if its user generated only the pass it to WebSocket
if (merchantKey.merchantType == MerchantTransaction.MerchantType.BRICK_AND_MORTAR) {
avgAlertNotificationPort.emit(getOutputData(data, String.format(brickMortarAlertMsg, txValue, change, lastSmaValue, merchantKey.merchantId, merchantKey.terminalId)));
} else { // its internet based
avgAlertNotificationPort.emit(getOutputData(data, String.format(internetAlertMsg, txValue, change, lastSmaValue, merchantKey.merchantId)));
}
//}
}
}
}
示例3: endWindow
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
/**
* Generates tuples for each key and emits them. Only keys that are in the
* denominator are iterated on If the key is only in the numerator, it gets
* ignored (cannot do divide by 0) Clears internal data
*/
@Override
public void endWindow()
{
HashMap<K, Double> tuples = new HashMap<K, Double>();
for (Map.Entry<K, MutableDouble> e : denominators.entrySet()) {
MutableDouble nval = numerators.get(e.getKey());
if (nval == null) {
tuples.put(e.getKey(), new Double(0.0));
} else {
tuples.put(e.getKey(), new Double((nval.doubleValue() / e.getValue()
.doubleValue()) * mult_by));
}
}
if (!tuples.isEmpty()) {
quotient.emit(tuples);
}
numerators.clear();
denominators.clear();
}
示例4: endWindow
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
/**
* Emits average for each key in end window. Data is computed during process
* on input port Clears the internal data before return.
*/
@Override
public void endWindow()
{
for (Map.Entry<K, MutableDouble> e : sums.entrySet()) {
K key = e.getKey();
double d = e.getValue().doubleValue();
if (doubleAverage.isConnected()) {
doubleAverage.emit(new KeyValPair<K, Double>(key, d / counts.get(key).doubleValue()));
}
if (intAverage.isConnected()) {
intAverage.emit(new KeyValPair<K, Integer>(key, (int)d));
}
if (longAverage.isConnected()) {
longAverage.emit(new KeyValPair<K, Long>(key, (long)d));
}
}
sums.clear();
counts.clear();
}
示例5: process
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
/**
* 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);
}
示例6: endWindow
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@Override
public void endWindow()
{
int totalWindowsOccupied = cacheOject.size();
for (Map.Entry<String, Map<String, KeyValPair<MutableDouble, Integer>>> e : outputMap.entrySet()) {
for (Map.Entry<String, KeyValPair<MutableDouble, Integer>> dimensionValObj : e.getValue().entrySet()) {
Map<String, DimensionObject<String>> outputData = new HashMap<String, DimensionObject<String>>();
KeyValPair<MutableDouble, Integer> keyVal = dimensionValObj.getValue();
if (operationType == AggregateOperation.SUM) {
outputData.put(e.getKey(), new DimensionObject<String>(keyVal.getKey(), dimensionValObj.getKey()));
} else if (operationType == AggregateOperation.AVERAGE) {
if (keyVal.getValue() != 0) {
double totalCount = ((double)(totalWindowsOccupied * applicationWindowSize)) / 1000;
outputData.put(e.getKey(), new DimensionObject<String>(new MutableDouble(keyVal.getKey().doubleValue() / totalCount), dimensionValObj.getKey()));
}
}
if (!outputData.isEmpty()) {
output.emit(outputData);
}
}
}
currentWindow = (currentWindow + 1) % windowSize;
}
示例7: process
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@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());
}
}
}
}
示例8: process
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@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);
}
}
}
示例9: process
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@Override
public void process(KeyValPair<MerchantKey, Double> tuple)
{
MutableDouble currentSma = currentSMAMap.get(tuple.getKey());
if (currentSma == null) { // first sma for the given key
double sma = tuple.getValue();
currentSMAMap.put(tuple.getKey(), new MutableDouble(sma));
//lastSMAMap.put(tuple.getKey(), new MutableDouble(sma));
} else { // move the current SMA value to the last SMA Map
//lastSMAMap.get(tuple.getKey()).setValue(currentSma.getValue());
currentSma.setValue(tuple.getValue()); // update the current SMA value
}
}
示例10: convertToNumber
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
protected Number convertToNumber(Object o)
{
if (o == null) {
return null;
} else if (o instanceof MutableDouble || o instanceof MutableLong) {
return (Number)o;
} else if (o instanceof Double || o instanceof Float) {
return new MutableDouble((Number)o);
} else if (o instanceof Number) {
return new MutableLong((Number)o);
} else {
return new MutableDouble(o.toString());
}
}
示例11: process
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
/**
* Process each key, compute change or percent, and emit it.
*/
@Override
public void process(KeyValPair<K, V> tuple)
{
K key = tuple.getKey();
if (!doprocessKey(key)) {
return;
}
MutableDouble bval = basemap.get(key);
if (bval != null) { // Only process keys that are in the basemap
double cval = tuple.getValue().doubleValue() - bval.doubleValue();
change.emit(new KeyValPair<K, V>(cloneKey(key), getValue(cval)));
percent.emit(new KeyValPair<K, Double>(cloneKey(key), (cval / bval.doubleValue()) * 100));
}
}
示例12: endWindow
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@Override
public void endWindow()
{
Map<String, DimensionObject<String>> outputAggregationsObject;
for (Entry<String, Map<String, Map<AggregateOperation, Number>>> keys : unifiedCache.entrySet()) {
String key = keys.getKey();
Map<String, Map<AggregateOperation, Number>> dimValues = keys.getValue();
for (Entry<String, Map<AggregateOperation, Number>> dimValue : dimValues.entrySet()) {
String dimValueName = dimValue.getKey();
Map<AggregateOperation, Number> operations = dimValue.getValue();
outputAggregationsObject = new HashMap<String, DimensionObject<String>>();
for (Entry<AggregateOperation, Number> operation : operations.entrySet()) {
AggregateOperation aggrOperationType = operation.getKey();
Number aggr = operation.getValue();
String outKey = key + "." + aggrOperationType.name();
DimensionObject<String> outDimObj = new DimensionObject<String>(new MutableDouble(aggr), dimValueName);
outputAggregationsObject.put(outKey, outDimObj);
}
aggregationsOutput.emit(outputAggregationsObject);
}
}
}
示例13: setup
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@Override
public void setup(OperatorContext arg0)
{
if (arg0 != null) {
applicationWindowSize = arg0.getValue(OperatorContext.APPLICATION_WINDOW_COUNT);
}
if (cacheOject == null) {
cacheOject = new HashMap<Integer, Map<String, Map<String, Number>>>(windowSize);
}
if (outputMap == null) {
outputMap = new HashMap<String, Map<String, KeyValPair<MutableDouble, Integer>>>();
}
setUpPatternList();
}
示例14: beginWindow
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@Override
public void beginWindow(long windowId)
{
dataMap = new HashMap<String, Map<String, MutableDouble>>();
// TODO Auto-generated method stub
}
示例15: endWindow
import org.apache.commons.lang.mutable.MutableDouble; //导入依赖的package包/类
@Override
public void endWindow()
{
for (Map.Entry<String, Map<String, MutableDouble>> e : dataMap.entrySet()) {
for (Map.Entry<String, MutableDouble> dimensionValObj : e.getValue().entrySet()) {
Map<String, DimensionObject<String>> outputData = new HashMap<String, DimensionObject<String>>();
outputData.put(e.getKey(), new DimensionObject<String>(dimensionValObj.getValue(), dimensionValObj.getKey()));
output.emit(outputData);
}
}
dataMap.clear();
}