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

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

Introduction

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

Prototype

public Object getValue() 

Source Link

Document

Gets the value as a Double instance.

Usage

From source file:com.datatorrent.contrib.frauddetect.AverageAlertingOperator.java

@Override
public void endWindow() {
    for (AverageAlertData data : alerts) {
        try {//from w w  w.  j  a v a2s .  c  o  m
            avgAlertOutputPort.emit(JsonUtils.toJson(data));
        } catch (IOException e) {
            logger.warn("Exception while converting object to JSON", e);
        }
    }

    alerts.clear();

    for (Map.Entry<MerchantKey, MutableDouble> entry : currentSMAMap.entrySet()) {
        MerchantKey key = entry.getKey();
        MutableDouble currentSma = entry.getValue();
        MutableDouble lastSma = lastSMAMap.get(key);
        if (lastSma == null) {
            lastSma = new MutableDouble(currentSma.doubleValue());
            lastSMAMap.put(key, lastSma);
        } else {
            lastSma.setValue(currentSma.getValue());
        }
    }
}

From source file:org.matsim.contrib.av.robotaxi.scoring.TaxiFareHandlerTest.java

/**
 * Test method for {@link org.matsim.contrib.av.robotaxi.scoring.TaxiFareHandler#TaxiFareHandler(org.matsim.core.config.Config)}.
 *///  ww w .  ja  v  a  2s .  co m
@Test
public void testTaxiFareHandler() {
    Network network = createNetwork();
    Config config = ConfigUtils.createConfig();
    TaxiFareConfigGroup tccg = new TaxiFareConfigGroup();
    config.addModule(tccg);
    tccg.setBasefare(1);
    tccg.setDailySubscriptionFee(1);
    tccg.setDistanceFare_m(1.0 / 1000.0);
    tccg.setTimeFare_h(36);
    DvrpConfigGroup dvrp = new DvrpConfigGroup();
    dvrp.setMode("taxi");
    config.addModule(dvrp);
    final MutableDouble fare = new MutableDouble(0);
    EventsManager events = EventsUtils.createEventsManager();
    TaxiFareHandler tfh = new TaxiFareHandler(config, events, network);
    events.addHandler(tfh);
    events.addHandler(new PersonMoneyEventHandler() {

        @Override
        public void handleEvent(PersonMoneyEvent event) {
            fare.add(event.getAmount());

        }

        @Override
        public void reset(int iteration) {
        }
    });
    Id<Person> p1 = Id.createPersonId("p1");
    Id<Vehicle> t1 = Id.createVehicleId("v1");
    events.processEvent(new PersonDepartureEvent(0.0, p1, Id.createLinkId("12"), dvrp.getMode()));
    events.processEvent(new PersonEntersVehicleEvent(60.0, p1, t1));
    events.processEvent(new LinkEnterEvent(61, t1, Id.createLinkId("23")));
    events.processEvent(new PersonArrivalEvent(120.0, p1, Id.createLinkId("23"), dvrp.getMode()));

    events.processEvent(new PersonDepartureEvent(180.0, p1, Id.createLinkId("12"), dvrp.getMode()));
    events.processEvent(new PersonEntersVehicleEvent(240.0, p1, t1));
    events.processEvent(new LinkEnterEvent(241, t1, Id.createLinkId("23")));
    events.processEvent(new PersonArrivalEvent(300.0, p1, Id.createLinkId("23"), dvrp.getMode()));

    //fare: 1 (daily fee) +2*1(basefare)+ 2*1 (distance) + (36/60)*2 = -(1+2+2+0,12) = -6.2 
    Assert.assertEquals(-6.2, fare.getValue());
}