Class SeriesSample

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

public final class SeriesSample extends HealthSample

A run of measurements that share one record identity -- a beat-to-beat heart-rate trace, a cadence series.

Why this type exists

The two platforms disagree about grouping. Health Connect's HeartRateRecord is a single record containing many samples, and deleting it means deleting the record as a whole. HealthKit returns the same data as many independent samples with no grouping at all.

Flattening Health Connect into individual samples loses the identity you need in order to delete; inventing a series on iOS would claim a grouping that is not there. So the choice is yours: SampleQuery.setFlattenSeries(boolean) defaults to true, which gives both platforms plain QuantitySample objects and lets cross-platform code be identical. Turn it off when you need record identity, and expect iOS to return series of size 1.

Storage

Values are held in parallel primitive arrays rather than a list of objects. A month of continuous heart rate is tens of thousands of points, and boxing each one is real memory pressure on a phone.

  • Method Details

    • create

      public static SeriesSample create(HealthDataType type, long startMillis, long endMillis, long[] sampleStarts, long[] sampleEnds, double[] values, HealthUnit unit)

      Creates a series. The three arrays must be the same length and are copied defensively.

      Throws
      • IllegalArgumentException: if the arrays are null, differ in length, or unit is null.
    • size

      public int size()
      The number of measurements in this series.
    • getSampleStartMillis

      public long getSampleStartMillis(int i)
      The start of measurement i, epoch millis UTC.
    • getSampleEndMillis

      public long getSampleEndMillis(int i)
      The end of measurement i, epoch millis UTC. Equal to the start for an instantaneous measurement.
    • getSampleValue

      public double getSampleValue(int i, HealthUnit in)

      Measurement i converted into in.

      Throws
      • IllegalArgumentException: if in measures a different dimension.
    • getUnit

      public HealthUnit getUnit()
      The unit every measurement in this series is expressed in.
    • toQuantitySample

      public QuantitySample toQuantitySample(int i)

      Measurement i as a standalone QuantitySample. Allocates, so prefer the indexed accessors when walking the whole series.

      The returned sample inherits this series' source, recording method and identifier -- meaning several extracted samples share one identifier, since they came from one record.

    • 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