public abstract class BaseMeasurement<TheUnit extends Unit> extends java.lang.Object implements Measurement
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
"pseudo-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.Measurement.Listener
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
long |
getAge()
Retrieve the age of this measurement.
|
long |
getBirthtime()
Return the creation time of this measurement;
|
static java.lang.Class<? extends Measurement> |
getClassForId(java.lang.String measurementId) |
abstract java.lang.String |
getGenericName() |
static MessageKey |
getKeyForMeasurement(java.lang.Class<? extends Measurement> measurementType) |
static Measurement |
getMeasurementFromMessage(java.lang.Class<? extends Measurement> measurementType,
SimpleVehicleMessage message) |
static Measurement |
getMeasurementFromMessage(SimpleVehicleMessage message) |
java.lang.String |
getName(android.content.Context context) |
Range<TheUnit> |
getRange()
Retrieve the valid range of the measurement.
|
java.lang.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.
|
java.lang.String |
toString() |
SimpleVehicleMessage |
toVehicleMessage() |
public BaseMeasurement(TheUnit value)
value
- the TheUnit this measurement represents.public BaseMeasurement(TheUnit value, Range<TheUnit> range)
value
- the TheUnit this measurement represents.range
- the valid Range
of values for this measurement.public abstract java.lang.String getGenericName()
getGenericName
in interface Measurement
public void setTimestamp(long timestamp)
Measurement
setTimestamp
in interface Measurement
timestamp
- the new timestamp, in milliseconds since the epoch.public long getAge()
Measurement
getAge
in interface Measurement
public long getBirthtime()
Measurement
getBirthtime
in interface Measurement
public boolean hasRange()
Measurement
hasRange
in interface Measurement
public Range<TheUnit> getRange()
Measurement
getRange
in interface Measurement
public TheUnit getValue()
Measurement
getValue
in interface Measurement
public java.lang.Object getSerializedValue()
Measurement
getSerializedValue
in interface Measurement
public SimpleVehicleMessage toVehicleMessage()
toVehicleMessage
in interface Measurement
public java.lang.String getName(android.content.Context context)
getName
in interface Measurement
public static MessageKey getKeyForMeasurement(java.lang.Class<? extends Measurement> measurementType) throws UnrecognizedMeasurementTypeException
public static java.lang.Class<? extends Measurement> getClassForId(java.lang.String measurementId) throws UnrecognizedMeasurementTypeException
public static Measurement getMeasurementFromMessage(SimpleVehicleMessage message) throws UnrecognizedMeasurementTypeException, NoValueException
public static Measurement getMeasurementFromMessage(java.lang.Class<? extends Measurement> measurementType, SimpleVehicleMessage message) throws UnrecognizedMeasurementTypeException, NoValueException
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object