# AggregationResult

# AggregationResult

Artifact:[androidx.health.connect:connect-client](https://developer.android.com/jetpack/androidx/releases/health-connect)  
[View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/aggregate/AggregationResult.kt+class:androidx.health.connect.client.aggregate.AggregationResult)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/health/connect/client/aggregate/AggregationResult "View this page in Java")

<br />

```
class AggregationResult
```

<br />

*** ** * ** ***

Contains results of requested[AggregateMetric](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric).

To retrieve aggregate metrics:  

```kotlin
val result = healthConnectClient.aggregate(
  metrics = setOf(Steps.COUNT_TOTAL, Distance.DISTANCE_TOTAL)
)
val totalSteps = result[Steps.COUNT_TOTAL]
val totalDistance = result[Distance.DISTANCE_TOTAL]
```  

|                                                                                     See also                                                                                      |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [aggregate](https://developer.android.com/reference/kotlin/androidx/health/connect/client/HealthConnectClient#aggregate(androidx.health.connect.client.request.AggregateRequest)) |   |

## Summary

|                                        ### Public functions                                         |
|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `operator `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)      | [contains](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#contains(androidx.health.connect.client.aggregate.AggregateMetric))`(metric: `[AggregateMetric](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric)`<*>)` Checks whether the aggregation result contains a metric or not.                                                              |
| `open operator `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [equals](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#equals(kotlin.Any))`(other: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)`                                                                                                                                                                                                                                  |
| `operator T?`                                                                                       | `<T : `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`> `[get](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#get(androidx.health.connect.client.aggregate.AggregateMetric))`(metric: `[AggregateMetric](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric)`<T>)` Retrieves a metric with given metric identifier. |
| `open `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                  | [hashCode](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#hashCode())`()`                                                                                                                                                                                                                                                                                                                             |
| `open `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)            | [toString](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#toString())`()`                                                                                                                                                                                                                                                                                                                             |

|                                                                                                ### Public properties                                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)`<`[DataOrigin](https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/DataOrigin)`>` | [dataOrigins](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#dataOrigins()) Set of[DataOrigin](https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/DataOrigin)s that contributed to the aggregation result. |

## Public functions

### contains

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)  

```
operator fun contains(metric: AggregateMetric<*>): Boolean
```

Checks whether the aggregation result contains a metric or not. If there is no relevant record that contribute to requested metric, the metric will not be provided.  

|                                                                Parameters                                                                 |
|-------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| `metric: `[AggregateMetric](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric)`<*>` | an aggregate metric identifier. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | whether given metric is set. |

### equals

```
open operator fun equals(other: Any?): Boolean
```  

### get

```
operator fun <T : Any> get(metric: AggregateMetric<T>): T?
```

Retrieves a metric with given metric identifier.

If there are no relevant records contributing to the requested metric, the metric will not be provided.  

| Returns |
|---------|----------------------------------------------|
| `T?`    | the value of the metric, or null if not set. |

|                                                                                         See also                                                                                         |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [contains](https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult#contains(androidx.health.connect.client.aggregate.AggregateMetric)) |   |

### hashCode

```
open fun hashCode(): Int
```  

### toString

```
open fun toString(): String
```  

## Public properties

### dataOrigins

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)  

```
val dataOrigins: Set<DataOrigin>
```

Set of[DataOrigin](https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/DataOrigin)s that contributed to the aggregation result.