当前位置: 首页>>代码示例>>Java>>正文


Java MutableDouble类代码示例

本文整理汇总了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);
  }
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:32,代码来源:SchemaMetrics.java

示例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)));

      }
      //}
    }
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:23,代码来源:AverageAlertingOperator.java

示例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();
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:25,代码来源:QuotientMap.java

示例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();
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:24,代码来源:AverageKeyVal.java

示例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);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:20,代码来源:SumKeyVal.java

示例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;

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:25,代码来源:MultiWindowDimensionAggregation.java

示例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());
      }
    }
  }

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:22,代码来源:DimensionAggregationUnifier.java

示例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);
    }
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:22,代码来源:DimensionTimeBucketSumOperator.java

示例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
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:14,代码来源:AverageAlertingOperator.java

示例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());
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:15,代码来源:NumberSummation.java

示例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));
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:18,代码来源:ChangeKeyVal.java

示例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);
    }

  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:31,代码来源:DimensionOperatorUnifier.java

示例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();

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:16,代码来源:MultiWindowDimensionAggregation.java

示例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

}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:8,代码来源:DimensionAggregationUnifier.java

示例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();
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:13,代码来源:DimensionAggregationUnifier.java


注:本文中的org.apache.commons.lang.mutable.MutableDouble类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。