public final class AggregateResult
- Object
- AggregateResult
One bucket of an AggregateQuery result: a span of time and the
metrics computed over it.
A missing value is null, never zero
get(HealthDataType,AggregateMetric) returns null when the bucket
held no data. That distinction matters: a day with no step data and a
day on which the user genuinely took no steps are different facts, and
collapsing them into 0 turns “we don’t know” into “you did nothing”.
Every health app that gets this wrong draws the same wrong chart –
a flat line through the days the phone was left at home.
HealthQuantity total = bucket.get(HealthDataType.STEPS, AggregateMetric.TOTAL);
if (total == null) {
renderNoDataMarker(bucket.getBucketStartMillis());
} else {
renderBar(total.getValue(HealthUnit.COUNT));
}
Constructors
public AggregateResult(long bucketStartMillis, long bucketEndMillis) | Creates an empty bucket spanning [start, end). |
Methods
public long getBucketStartMillis() | Inclusive start of this bucket, epoch millis UTC. |
public long getBucketEndMillis() | Exclusive end of this bucket, epoch millis UTC. |
public HealthQuantity get(HealthDataType type, AggregateMetric metric) | The computed value, or null when this bucket held no data for that type and metric. |
public int getSampleCount(HealthDataType type) | How many samples contributed to type in this bucket. |
public boolean isEmpty() | true when no metric in this bucket produced a value. |
public void put(HealthDataType type, AggregateMetric metric, HealthQuantity value) | Records a computed value. |
public void setSampleCount(HealthDataType type, int count) | Records how many samples contributed to type. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
AggregateResult
public AggregateResult(long bucketStartMillis, long bucketEndMillis)Creates an empty bucket spanning
[start, end).Method details
getBucketStartMillis
public long getBucketStartMillis()Inclusive start of this bucket, epoch millis UTC.
getBucketEndMillis
public long getBucketEndMillis()Exclusive end of this bucket, epoch millis UTC.
get
public HealthQuantity get(HealthDataType type, AggregateMetric metric)The computed value, or
null when this bucket held no data for
that type and metric. See the class documentation – do not
substitute zero.getSampleCount
public int getSampleCount(HealthDataType type)How many samples contributed to
type in this bucket. Zero is a
real answer here, unlike get(HealthDataType,AggregateMetric).isEmpty
public boolean isEmpty()true when no metric in this bucket produced a value.put
public void put(HealthDataType type, AggregateMetric metric, HealthQuantity value)Records a computed value. Called by
HealthStore and by ports; a
null value clears the entry rather than storing a placeholder.setSampleCount
public void setSampleCount(HealthDataType type, int count)Records how many samples contributed to
type.toString
public String toString()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())