package com.openxc.measurements;

import com.openxc.units.Unit;
import com.openxc.util.Range;

/**
 * The MeasurementInterface is the base for all OpenXC measurements.
 *
 * A Measurement has at least a value and an age, and optionally a range of
 * valid values.
 */
public interface MeasurementInterface {
    public interface Listener {
        public void receive(MeasurementInterface measurement);
    }

    /**
     * Retreive the age of this measurement.
     *
     * @return the age of the data in seconds.
     */
    public double getAge();

    /**
     * Set the birth timestamp for this measurement.
     *
     */
    public void setTimestamp(double timestamp);

    /**
     * Determine if this measurement has a valid range.
     *
     * @return true if the measurement has a non-null range.
     */
    public boolean hasRange();

    /**
     * Retrieve the valid range of the measurement.
     *
     * @return the Range of the measurement
     * @throws NoRangeException if the measurement doesn't have a range.
     */
    public Range<? extends Unit> getRange() throws NoRangeException;

    /**
     * Return the value of this measurement.
     *
     * @return The wrapped value (an instance of TheUnit)
     */
    public Unit getValue();

    public Object getSerializedValue();

    // TODO argh, no easy way to get a type for this without having two template
    // parameters
    public Object getEvent();

    public Object getSerializedEvent();
}

@@ -1269,51 +1269,1155 @@
     
-public Object getSerializedValue();%0A%0A    //
+/**%0A     * Return the value of this measurement as a type good for serialization.%0A     *%0A     * This is required because we go through this process with each%0A     * measurement:%0A     *%0A     *     - Incoming JSON is parsed to String, boolean, double, and int.%0A     *     - All types are converted to double by RawMeasurement in order to fit%0A     *     over AIDL (TODO this seems really, really wrong and adds a ton of%0A     *     complication - I know I spent 2 or 3 days on trying to do templated%0A     *     classes over AIDL and it just didn't seem to work, but there must be%0A     *     a better way)%0A     *     - Converted to full Measurement in VehicleService (the specific%0A     *     Measurement classes know how to convert from a double back to the%0A     *     real value.%0A     *     - Output the original values (as if they were directly from JSON)%0A     *     form the Measurement for the data sinks in the VehicleService.%0A     *%0A     * @return something easily serializable - e.g. String, Double, Boolean.%0A     */%0A    public Object getSerializedValue();%0A%0A    /**%0A     * Return an optional event associated with this measurement.%0A     *%0A     *
  TOD
@@ -2495,10 +2495,10 @@
     
-//
+ *
  par
@@ -2508,39 +2508,235 @@
 ters
-%0A    public Object getEvent();%0A
+. can we have an optional template parameter in Java?%0A     */%0A    public Object getEvent();%0A%0A    /**%0A     * Return the event of this measurement as a type good for serialization.%0A     *%0A     * @see #getSerializedValue()%0A     */
 %0A   

Document the new serialized value/event methods on Measurement.