-
Notifications
You must be signed in to change notification settings - Fork 41
/
AggregationResults.java
104 lines (90 loc) · 3.23 KB
/
AggregationResults.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.datastore;
import static com.google.api.client.util.Preconditions.checkNotNull;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.cloud.Timestamp;
import com.google.cloud.datastore.models.ExplainMetrics;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* The result of an {@link AggregationQuery} query submission. Contains a List<{@link
* AggregationResult}> and readTime {@link Timestamp} in it.
*
* <p>This can be used to iterate over an underlying List<{@link AggregationResult}> directly.
*/
public class AggregationResults implements Iterable<AggregationResult> {
private final List<AggregationResult> aggregationResults;
private final Timestamp readTime;
private final ExplainMetrics explainMetrics;
@BetaApi
public AggregationResults(
List<AggregationResult> aggregationResults,
Timestamp readTime,
ExplainMetrics explainMetrics) {
checkNotNull(aggregationResults, "Aggregation results cannot be null");
checkNotNull(readTime, "readTime cannot be null");
this.aggregationResults = aggregationResults;
this.readTime = readTime;
this.explainMetrics = explainMetrics;
}
public AggregationResults(List<AggregationResult> aggregationResults, Timestamp readTime) {
this(aggregationResults, readTime, null);
}
/** Returns {@link Iterator} for underlying List<{@link AggregationResult}>. */
@Override
public Iterator<AggregationResult> iterator() {
return this.aggregationResults.iterator();
}
public int size() {
return this.aggregationResults.size();
}
/**
* Returns {@code ExplainMetrics} if {@code ExplainOptions} were enabled. Otherwise, returns null.
*/
@BetaApi
public Optional<ExplainMetrics> getExplainMetrics() {
return Optional.ofNullable(this.explainMetrics);
}
@InternalApi
public AggregationResult get(int index) {
return this.aggregationResults.get(index);
}
/** Returns read timestamp this result batch was returned from. */
public Timestamp getReadTime() {
return this.readTime;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AggregationResults that = (AggregationResults) o;
return Objects.equals(aggregationResults, that.aggregationResults)
&& Objects.equals(readTime, that.readTime)
&& Objects.equals(explainMetrics, that.explainMetrics);
}
@Override
public int hashCode() {
return Objects.hash(aggregationResults, readTime, explainMetrics);
}
}