Example usage for org.apache.commons.lang.mutable MutableDouble increment

List of usage examples for org.apache.commons.lang.mutable MutableDouble increment

Introduction

In this page you can find the example usage for org.apache.commons.lang.mutable MutableDouble increment.

Prototype

public void increment() 

Source Link

Document

Increments the value.

Usage

From source file:com.datatorrent.lib.counters.BasicCountersTest.java

@Test
public void testBasicCounters() throws InstantiationException, IllegalAccessException {
    BasicCounters<MutableDouble> doubleBasicCounters = new BasicCounters<MutableDouble>(MutableDouble.class);
    MutableDouble counterA = doubleBasicCounters.findCounter(CounterKeys.A);

    counterA.increment();

    MutableDouble counterAInCounters = doubleBasicCounters.getCounter(CounterKeys.A);
    Assert.assertNotNull("null", doubleBasicCounters.getCounter(CounterKeys.A));
    Assert.assertTrue("equality", counterAInCounters.equals(counterA));
    Assert.assertEquals(counterA.doubleValue(), 1.0, 0);
}

From source file:com.datatorrent.lib.counters.BasicCountersTest.java

@Test
public void testBasicCountersAggregator() throws InstantiationException, IllegalAccessException {
    List<Object> physicalCounters = Lists.newArrayList();

    for (int i = 0; i < 5; i++) {
        BasicCounters<MutableDouble> doubleBasicCounters = new BasicCounters<MutableDouble>(
                MutableDouble.class);
        MutableDouble counterA = doubleBasicCounters.findCounter(CounterKeys.A);
        counterA.increment();

        physicalCounters.add(doubleBasicCounters);
    }//from w ww.  java2s .  c o m

    BasicCounters.DoubleAggregator<MutableDouble> aggregator = new BasicCounters.DoubleAggregator<MutableDouble>();
    @SuppressWarnings("unchecked")
    Map<String, NumberAggregate.DoubleAggregate> aggregateMap = (Map<String, NumberAggregate.DoubleAggregate>) aggregator
            .aggregate(physicalCounters);

    Assert.assertNotNull("null", aggregateMap.get(CounterKeys.A.name()));
    NumberAggregate.DoubleAggregate aggregate = aggregateMap.get(CounterKeys.A.name());

    Assert.assertEquals(aggregate.getSum().doubleValue(), 5.0, 0);
    Assert.assertEquals(aggregate.getMin().doubleValue(), 1.0, 0);
    Assert.assertEquals(aggregate.getMax().doubleValue(), 1.0, 0);
    Assert.assertEquals(aggregate.getAvg().doubleValue(), 1.0, 0);
}

From source file:com.datatorrent.lib.math.QuotientMap.java

/**
 * Add/Update entry to key/sum value map.
 * /* w w  w . ja  v  a 2  s.c  om*/
 * @param key
 *          name.
 * @param value
 *          value for key.
 * @param map
 *          numerator/denominator key/sum map.
 */
public void addEntry(K key, V value, Map<K, MutableDouble> map) {
    if (!doprocessKey(key) || (value == null)) {
        return;
    }
    MutableDouble val = map.get(key);
    if (val == null) {
        if (countkey) {
            val = new MutableDouble(1.00);
        } else {
            val = new MutableDouble(value.doubleValue());
        }
    } else {
        if (countkey) {
            val.increment();
        } else {
            val.add(value.doubleValue());
        }
    }
    map.put(cloneKey(key), val);
}