Example usage for org.joda.time.base AbstractInstant getMillis

List of usage examples for org.joda.time.base AbstractInstant getMillis

Introduction

In this page you can find the example usage for org.joda.time.base AbstractInstant getMillis.

Prototype

long getMillis();

Source Link

Document

Get the value as the number of milliseconds since the epoch, 1970-01-01T00:00:00Z.

Usage

From source file:org.powertac.common.Rate.java

License:Apache License

/**
 * Returns the rate for some time in the past or future, regardless of
 * whether the Rate applies at that time, and regardless of whether
 * the requested time is beyond the notification interval of a
 * variable rate. If helper is given, and this rate is not fixed, and
 * there is not an HourlyCharge for the requested timeslot, then 
 * the helper is used to produce the value. 
 *///from w w  w.ja  v a  2 s .co  m
public double getValue(AbstractInstant when, TariffEvaluationHelper helper) {
    if (fixed)
        return minValue;
    else if (null != helper) {
        return helper.getWeightedValue(this);
    } else if (rateHistory.size() == 0) {
        log.debug("no rate history, return default");
        return expectedMean;
    } else {
        if (probe == null) {
            probe = new ProbeCharge(new Instant(0l), 0.0);
        }
        Instant inst = new Instant(when);
        // return the most recent price announcement for the given time
        probe.setAtTime(inst.plus(1000l));
        SortedSet<HourlyCharge> head = rateHistory.headSet(probe);
        if (head == null || head.size() == 0) {
            log.debug("No hourly charge found for " + when.getMillis() + ", returning default");
            return expectedMean; // default
        } else {
            HourlyCharge candidate = head.last();
            if (candidate.getAtTime().getMillis() == inst.getMillis()) {
                return candidate.getValue();
            } else {
                return expectedMean; // default
            }
        }
    }
}