Class QuantitySample
java.lang.Object
com.codename1.health.HealthSample
com.codename1.health.QuantitySample
A numeric measurement with a unit -- the most common kind of health sample.
QuantitySample weight = QuantitySample.create(
HealthDataType.BODY_MASS,
new HealthQuantity(72.5, HealthUnit.KILOGRAM),
System.currentTimeMillis());
weight.setRecordingMethod(RecordingMethod.MANUAL_ENTRY);
-
Method Summary
Modifier and TypeMethodDescriptionstatic QuantitySamplecreate(HealthDataType type, HealthQuantity quantity, long instantMillis) An instantaneous measurement.static QuantitySamplecreate(HealthDataType type, HealthQuantity quantity, long startMillis, long endMillis) A measurement spanning an interval.The measured value together with its unit.doublegetValue(HealthUnit unit) Shorthand forgetQuantity().getValue(unit).toString()Returns a string representation of the object.Methods inherited from class HealthSample
equals, getDurationMillis, getEndMillis, getId, getMetadata, getRecordingMethod, getSource, getStartMillis, getType, hashCode, isInstantaneous, putMetadata, setId, setRecordingMethod, setSource
-
Method Details
-
create
public static QuantitySample create(HealthDataType type, HealthQuantity quantity, long instantMillis) An instantaneous measurement.
Throws
IllegalArgumentException: if the type is interval-only, such asHealthDataType.STEPS-- a step count belongs to a span of time, never to a moment.
-
create
public static QuantitySample create(HealthDataType type, HealthQuantity quantity, long startMillis, long endMillis) A measurement spanning an interval. -
getQuantity
The measured value together with its unit. Read a number out of it withHealthQuantity.getValue(HealthUnit), which forces the unit to be named at the call site. -
getValue
Shorthand for
getQuantity().getValue(unit).Throws
IllegalArgumentException: ifunitmeasures a different dimension than this sample's value.
-
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())- Overrides:
toStringin classHealthSample
-