List of usage examples for org.apache.commons.lang.mutable MutableDouble MutableDouble
public MutableDouble(Number value)
From source file:com.datatorrent.lib.multiwindow.SimpleMovingAverageObject.java
public SimpleMovingAverageObject() { sum = new MutableDouble(0); count = new MutableInt(0); }
From source file:com.datatorrent.contrib.redis.NumberSummation.java
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 {// ww w. j a va 2 s. c om return new MutableDouble(o.toString()); } }
From source file:com.datatorrent.apps.logstream.DimensionOperatorUnifierTest.java
@Test @SuppressWarnings("unchecked") public void testOperator() { DimensionOperatorUnifier unifier = new DimensionOperatorUnifier(); CollectorTestSink sink = new CollectorTestSink(); unifier.aggregationsOutput.setSink(sink); unifier.beginWindow(1);/*from w w w . j a va 2 s. c o m*/ Map<String, DimensionObject<String>> tuple1 = new HashMap<String, DimensionObject<String>>(); tuple1.put("m|201402121900|0|65537|131074|bytes.AVERAGE", new DimensionObject<String>(new MutableDouble(75), "a")); tuple1.put("m|201402121900|0|65537|131074|bytes.COUNT", new DimensionObject<String>(new MutableDouble(3.0), "a")); tuple1.put("m|201402121900|0|65537|131074|bytes.SUM", new DimensionObject<String>(new MutableDouble(225), "a")); Map<String, DimensionObject<String>> tuple2 = new HashMap<String, DimensionObject<String>>(); tuple2.put("m|201402121900|0|65537|131074|bytes.AVERAGE", new DimensionObject<String>(new MutableDouble(50), "a")); tuple2.put("m|201402121900|0|65537|131074|bytes.COUNT", new DimensionObject<String>(new MutableDouble(2.0), "a")); tuple2.put("m|201402121900|0|65537|131074|bytes.SUM", new DimensionObject<String>(new MutableDouble(100), "a")); Map<String, DimensionObject<String>> tuple3 = new HashMap<String, DimensionObject<String>>(); tuple3.put("m|201402121900|0|65537|131074|bytes.AVERAGE", new DimensionObject<String>(new MutableDouble(50), "z")); tuple3.put("m|201402121900|0|65537|131074|bytes.COUNT", new DimensionObject<String>(new MutableDouble(2.0), "z")); tuple3.put("m|201402121900|0|65537|131074|bytes.SUM", new DimensionObject<String>(new MutableDouble(100), "z")); Map<String, DimensionObject<String>> tuple4 = new HashMap<String, DimensionObject<String>>(); tuple4.put("m|201402121900|0|65537|131075|bytes.AVERAGE", new DimensionObject<String>(new MutableDouble(14290.5), "b")); tuple4.put("m|201402121900|0|65537|131075|bytes.COUNT", new DimensionObject<String>(new MutableDouble(2.0), "b")); tuple4.put("m|201402121900|0|65537|131075|bytes.SUM", new DimensionObject<String>(new MutableDouble(28581.0), "b")); Map<String, DimensionObject<String>> tuple5 = new HashMap<String, DimensionObject<String>>(); tuple5.put("m|201402121900|0|65537|131076|bytes.AVERAGE", new DimensionObject<String>(new MutableDouble(290.75), "c")); tuple5.put("m|201402121900|0|65537|131076|bytes.COUNT", new DimensionObject<String>(new MutableDouble(10.0), "c")); tuple5.put("m|201402121900|0|65537|131076|bytes.SUM", new DimensionObject<String>(new MutableDouble(8581.0), "c")); unifier.process(tuple1); unifier.process(tuple2); unifier.process(tuple3); unifier.process(tuple4); unifier.process(tuple5); unifier.endWindow(); @SuppressWarnings("unchecked") List<Map<String, DimensionObject<String>>> tuples = sink.collectedTuples; Assert.assertEquals("Tuple Count", 4, tuples.size()); for (Map<String, DimensionObject<String>> map : tuples) { for (Entry<String, DimensionObject<String>> entry : map.entrySet()) { String key = entry.getKey(); DimensionObject<String> dimObj = entry.getValue(); if (key.equals("m|201402121900|0|65537|131074|bytes.AVERAGE") && dimObj.getVal().equals("a")) { Assert.assertEquals("average for key " + key + " and dimension key " + "a", new MutableDouble(65), dimObj.getCount()); } if (key.equals("m|201402121900|0|65537|131074|bytes.SUM") && dimObj.getVal().equals("z")) { Assert.assertEquals("sum for key " + key + " and dimension key " + "z", new MutableDouble(100), dimObj.getCount()); } if (key.equals("m|201402121900|0|65537|131076|bytes.COUNT") && dimObj.getVal().equals("c")) { Assert.assertEquals("count for key " + key + " and dimension key " + "c", new MutableDouble(10), dimObj.getCount()); } } } }
From source file:com.datatorrent.apps.logstream.LogstreamTopNTest.java
@Test @SuppressWarnings("unchecked") public void testOperator() { LogstreamTopN oper = new LogstreamTopN(); LogstreamPropertyRegistry registry = new LogstreamPropertyRegistry(); registry.bind(LogstreamUtil.LOG_TYPE, "apache"); registry.bind(LogstreamUtil.FILTER, "default"); oper.setRegistry(registry);//w w w . j a v a2s . co m oper.setN(5); CollectorTestSink mapSink = new CollectorTestSink(); oper.top.setSink(mapSink); oper.beginWindow(0); Map<String, DimensionObject<String>> tuple1 = new HashMap<String, DimensionObject<String>>(); DimensionObject<String> dimObja = new DimensionObject<String>(new MutableDouble(10), "a"); tuple1.put("m|201402121900|0|65535|131075|val.COUNT", dimObja); oper.data.process(tuple1); DimensionObject<String> dimObjb = new DimensionObject<String>(new MutableDouble(1), "b"); tuple1.put("m|201402121900|0|65535|131075|val.COUNT", dimObjb); oper.data.process(tuple1); DimensionObject<String> dimObjc = new DimensionObject<String>(new MutableDouble(5), "c"); tuple1.put("m|201402121900|0|65535|131075|val.COUNT", dimObjc); oper.data.process(tuple1); DimensionObject<String> dimObjd = new DimensionObject<String>(new MutableDouble(2), "d"); tuple1.put("m|201402121900|0|65535|131075|val.COUNT", dimObjd); oper.data.process(tuple1); DimensionObject<String> dimObje = new DimensionObject<String>(new MutableDouble(15), "e"); tuple1.put("m|201402121900|0|65535|131075|val.COUNT", dimObje); oper.data.process(tuple1); DimensionObject<String> dimObjf = new DimensionObject<String>(new MutableDouble(4), "f"); tuple1.put("m|201402121900|0|65535|131075|val.COUNT", dimObjf); oper.data.process(tuple1); oper.endWindow(); @SuppressWarnings("unchecked") Map<String, List<DimensionObject<String>>> tuples = (Map<String, List<DimensionObject<String>>>) mapSink.collectedTuples .get(0); List<DimensionObject<String>> outList = tuples.get("m|201402121900|0|65535|131075|val.COUNT"); List<DimensionObject<String>> expectedList = new ArrayList<DimensionObject<String>>(); expectedList.add(dimObje); expectedList.add(dimObja); expectedList.add(dimObjc); expectedList.add(dimObjf); expectedList.add(dimObjd); Assert.assertEquals("Size", expectedList.size(), outList.size()); Assert.assertEquals("compare list", expectedList, outList); }
From source file:com.datatorrent.lib.util.DimensionTimeBucketSumOperator.java
@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;/*w ww . j av a 2 s . c om*/ } 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); } } }
From source file:com.datatorrent.lib.logs.TopNUniqueSiteStatsTest.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(TopNUnique oper) {
CollectorTestSink sortSink = new CollectorTestSink();
oper.top.setSink(sortSink);/*from www .ja va2 s . c o m*/
oper.setN(3);
oper.beginWindow(0);
HashMap<String, DimensionObject<String>> input = new HashMap<String, DimensionObject<String>>();
input.put("url", new DimensionObject<String>(new MutableDouble(10), "abc"));
oper.data.process(input);
input.clear();
input.put("url", new DimensionObject<String>(new MutableDouble(1), "def"));
input.put("url1", new DimensionObject<String>(new MutableDouble(1), "def"));
oper.data.process(input);
input.clear();
input.put("url", new DimensionObject<String>(new MutableDouble(101), "ghi"));
input.put("url1", new DimensionObject<String>(new MutableDouble(101), "ghi"));
oper.data.process(input);
input.clear();
input.put("url", new DimensionObject<String>(new MutableDouble(50), "jkl"));
oper.data.process(input);
input.clear();
input.put("url", new DimensionObject<String>(new MutableDouble(50), "jkl"));
input.put("url3", new DimensionObject<String>(new MutableDouble(50), "jkl"));
oper.data.process(input);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 3, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
log.debug(o.toString());
}
log.debug("Done testing round\n");
}
From source file:com.datatorrent.lib.logs.MultiWindowDimensionAggregationTest.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testNodeProcessingSchema(MultiWindowDimensionAggregation oper) {
oper.setWindowSize(3);//from w w w . ja va2s. c o m
List<int[]> dimensionArrayList = new ArrayList<int[]>();
int[] dimensionArray = { 0, 1 };
int[] dimensionArray_2 = { 0 };
dimensionArrayList.add(dimensionArray);
dimensionArrayList.add(dimensionArray_2);
oper.setDimensionArray(dimensionArrayList);
oper.setTimeBucket("m");
oper.setDimensionKeyVal("0");
oper.setOperationType(AggregateOperation.AVERAGE);
oper.setup(null);
CollectorTestSink sortSink = new CollectorTestSink();
oper.output.setSink(sortSink);
oper.beginWindow(0);
Map<String, Map<String, Number>> data_0 = new HashMap<String, Map<String, Number>>();
Map<String, Number> input_0 = new HashMap<String, Number>();
input_0.put("0", new MutableDouble(9));
input_0.put("1", new MutableDouble(9));
input_0.put("2", new MutableDouble(9));
data_0.put("m|20130823131512|0:abc|1:ff", input_0);
data_0.put("m|20130823131512|0:abc", input_0);
data_0.put("m|20130823131512|0:abc|1:ie", input_0);
Map<String, Number> input_new = new HashMap<String, Number>();
input_new.put("0", new MutableDouble(19));
input_new.put("1", new MutableDouble(19));
input_new.put("2", new MutableDouble(19));
data_0.put("m|20130823131512|0:def|1:ie", input_new);
oper.data.process(data_0);
oper.endWindow();
Map<String, Map<String, Number>> data_1 = new HashMap<String, Map<String, Number>>();
Map<String, Number> input_1 = new HashMap<String, Number>();
oper.beginWindow(1);
input_1.put("0", new MutableDouble(9));
input_1.put("1", new MutableDouble(9));
input_1.put("2", new MutableDouble(9));
data_1.put("m|20130823131513|0:def|1:ff", input_1);
data_1.put("m|20130823131513|0:abc|1:ie", input_1);
oper.data.process(data_1);
oper.endWindow();
Map<String, Map<String, Number>> data_2 = new HashMap<String, Map<String, Number>>();
Map<String, Number> input_2 = new HashMap<String, Number>();
oper.beginWindow(2);
input_2.put("0", new MutableDouble(19));
input_2.put("1", new MutableDouble(19));
input_2.put("2", new MutableDouble(19));
data_2.put("m|20130823131514|0:def|1:ff", input_2);
data_2.put("m|20130823131514|0:abc|1:ie", input_2);
oper.data.process(data_2);
oper.endWindow();
Map<String, Map<String, Number>> data_3 = new HashMap<String, Map<String, Number>>();
Map<String, Number> input_3 = new HashMap<String, Number>();
oper.beginWindow(3);
input_3.put("0", new MutableDouble(19));
input_3.put("1", new MutableDouble(19));
input_3.put("2", new MutableDouble(19));
data_3.put("m|20130823131514|0:def|1:ff", input_3);
data_3.put("m|20130823131514|0:abc|1:ie", input_3);
oper.data.process(data_3);
oper.endWindow();
Assert.assertEquals("number emitted tuples", 16, sortSink.collectedTuples.size());
for (Object o : sortSink.collectedTuples) {
logger.debug(o.toString());
}
logger.debug("Done testing round\n");
}
From source file:eu.project.ttc.models.Context.java
public void setCoOccurrences(String term, double coOccurrences, int mode) { if (!occurrences.containsKey(term)) occurrences.put(term, new MutableDouble(0.0)); MutableDouble coOcc = occurrences.get(term); if (mode == DEL_MODE) { coOcc.setValue(coOccurrences);//w ww . ja v a 2s .c o m } else if (mode == ADD_MODE) { coOcc.add(coOccurrences); } else if (mode == MAX_MODE && coOccurrences > coOcc.doubleValue()) { coOcc.setValue(coOccurrences); } else if (mode == MIN_MODE && coOccurrences < coOcc.doubleValue()) { coOcc.setValue(coOccurrences); } }
From source file:com.datatorrent.lib.util.DimensionTimeBucketSumOperatorTest.java
@Test public void testDimensionTimeBucket() throws InterruptedException { DimensionTimeBucketSumOperator oper = new DimensionTimeBucketSumOperator(); CollectorTestSink sortSink = new CollectorTestSink(); oper.out.setSink(sortSink);//from ww w . j a v a2 s. co m oper.addDimensionKeyName("ipAddr"); oper.addDimensionKeyName("url"); oper.addDimensionKeyName("status"); oper.addDimensionKeyName("agent"); oper.addValueKeyName("bytes"); Set<String> dimensionKey = new HashSet<String>(); dimensionKey.add("ipAddr"); dimensionKey.add("url"); try { oper.addCombination(dimensionKey); } catch (NoSuchFieldException e) { //ignored } oper.setTimeBucketFlags(AbstractDimensionTimeBucketOperator.TIMEBUCKET_MINUTE); oper.setup(null); oper.beginWindow(0); oper.in.process(getMap("10.10.1.1", "/movies", "200", "FF", 20)); oper.in.process(getMap("10.10.1.2", "/movies", "200", "FF", 20)); oper.in.process(getMap("10.10.1.2", "/movies", "200", "FF", 20)); oper.endWindow(); Map<String, Map<String, Number>> outputMap = Maps.newHashMap(); Map<String, Number> key1 = Maps.newHashMap(); key1.put("1", new MutableDouble(40.0)); key1.put("0", new MutableDouble(2.0)); outputMap.put("m|197001010000|0:10.10.1.2|1:/movies", key1); Map<String, Number> key2 = Maps.newHashMap(); key2.put("0", new MutableDouble(1.0)); key2.put("1", new MutableDouble(20.0)); outputMap.put("m|197001010000|0:10.10.1.1|1:/movies", key2); Assert.assertEquals("number emitted tuples", 1, sortSink.collectedTuples.size()); for (Object o : sortSink.collectedTuples) { Assert.assertEquals("content of tuple ", outputMap, o); logger.debug(o.toString()); } logger.debug("Done testing round\n"); }
From source file:com.datatorrent.lib.math.MarginMap.java
/** * Adds the value for each key.//from w w w . java 2s .c o m * @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()); } }