# Class QuantitySample

java.lang.Object
com.codename1.health.HealthSample
com.codename1.health.QuantitySample

public final class QuantitySample extends HealthSample

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 Type
  Method
  Description
  `static QuantitySample`
  `create(HealthDataType type, HealthQuantity quantity, long instantMillis)`
  An instantaneous measurement.
  `static QuantitySample`
  `create(HealthDataType type, HealthQuantity quantity, long startMillis, long endMillis)`
  A measurement spanning an interval.
  `HealthQuantity`
  `getQuantity()`
  The measured value together with its unit.
  `double`
  `getValue(HealthUnit unit)`
  Shorthand for `getQuantity().getValue(unit)`.
  `String`
  `toString()`
  Returns a string representation of the object.

  ### Methods inherited from class HealthSample

  `equals, getDuration, getDurationMillis, getEnd, getEndMillis, getId, getMetadata, getRecordingMethod, getSource, getStart, getStartMillis, getType, hashCode, isInstantaneous, putMetadata, setId, setRecordingMethod, setSource`

  ### Methods inherited from class Object

  `clone, getClass, notify, notifyAll, wait, wait, wait`

- ## 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 as `HealthDataType.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

    public HealthQuantity getQuantity()
    The measured value together with its unit. Read a number out of it with `HealthQuantity.getValue(HealthUnit)`, which forces the unit to be named at the call site.

  - ### getValue

    public double getValue(HealthUnit unit)

    Shorthand for `getQuantity().getValue(unit)`.

    ###### Throws

    - `IllegalArgumentException`: if `unit` measures a different dimension than this sample's value.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns 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:
      `toString` in class `HealthSample`