public abstract class

BaseMeasurement

extends Object
implements Measurement
java.lang.Object
   ↳ com.openxc.measurements.BaseMeasurement<TheUnit extends com.openxc.units.Unit>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

The BaseMeasurement is the base implementation of the Measurement, and wraps an instance of a Unit, and the value it returns is always in terms of this Unit. The Unit wrapper might seem annoying at first, but it is critical to avoid misinterpreting the unit and crashing your lander into Mars (http://en.wikipedia.org/wiki/Mars_Climate_Orbiter). Most applications will not use this class directly, but will import specific child classes that correspond to specific types of measurements - i.e. the parameterized instances of this class with a Unit. That may seem like a "psuedo-typedef" but we're using it to enforce the binding between the measurement and its unit type. This unfortunately means we have to add constructors to every child class because they aren't inherited from Measurement. If you know of a better way, please say so.

Summary

Fields
protected AgingData<TheUnit extends Unit> mValue
Public Constructors
BaseMeasurement(TheUnit value)
Construct a new Measurement with the given value.
BaseMeasurement(TheUnit value, Range<TheUnit> range)
Construct an new Measurement with the given value and valid Range.
Public Methods
boolean equals(Object obj)
long getAge()
Retreive the age of this measurement.
long getBirthtime()
Return the creation time of this measurement;
static Class<? extends Measurement> getClassForId(String measurementId)
abstract String getGenericName()
static MessageKey getKeyForMeasurement(Class<? extends Measurement> measurementType)
static Measurement getMeasurementFromMessage(SimpleVehicleMessage message)
static Measurement getMeasurementFromMessage(Class<? extends Measurement> measurementType, SimpleVehicleMessage message)
String getName(Context context)
Range<TheUnit> getRange()
Retrieve the valid range of the measurement.
Object getSerializedValue()
Return the value of this measurement as a type good for serialization.
TheUnit getValue()
Return the value of this measurement.
boolean hasRange()
Determine if this measurement has a valid range.
void setTimestamp(long timestamp)
Set the birth timestamp for this measurement.
String toString()
SimpleVehicleMessage toVehicleMessage()
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.openxc.measurements.Measurement

Fields

protected AgingData<TheUnit extends Unit> mValue

Public Constructors

public BaseMeasurement (TheUnit value)

Construct a new Measurement with the given value.

Parameters
value the TheUnit this measurement represents.

public BaseMeasurement (TheUnit value, Range<TheUnit> range)

Construct an new Measurement with the given value and valid Range. There is not currently any automated verification that the value is within the range - this is up to the application programmer.

Parameters
value the TheUnit this measurement represents.
range the valid Range of values for this measurement.

Public Methods

public boolean equals (Object obj)

public long getAge ()

Retreive the age of this measurement.

Returns
  • the age of the data in milliseconds.

public long getBirthtime ()

Return the creation time of this measurement;

Returns
  • the creation time in milliseconds since the epoch of this measurement.

public static Class<? extends Measurement> getClassForId (String measurementId)

public abstract String getGenericName ()

public static MessageKey getKeyForMeasurement (Class<? extends Measurement> measurementType)

public static Measurement getMeasurementFromMessage (SimpleVehicleMessage message)

public static Measurement getMeasurementFromMessage (Class<? extends Measurement> measurementType, SimpleVehicleMessage message)

public String getName (Context context)

public Range<TheUnit> getRange ()

Retrieve the valid range of the measurement.

Returns
  • the Range of the measurement or null if none.

public Object getSerializedValue ()

Return the value of this measurement as a type good for serialization.

Returns
  • something easily serializable - e.g. String, Double, Boolean.

public TheUnit getValue ()

Return the value of this measurement.

Returns
  • The wrapped value (an instance of TheUnit)

public boolean hasRange ()

Determine if this measurement has a valid range.

Returns
  • true if the measurement has a non-null range.

public void setTimestamp (long timestamp)

Set the birth timestamp for this measurement.

Parameters
timestamp the new timestamp, in milliseconds since the epoch.

public String toString ()

public SimpleVehicleMessage toVehicleMessage ()