2525 * {@link Aggregation} is the process of combining a certain set of {@code MeasureValue}s for a
2626 * given {@code Measure} into an {@link AggregationData}.
2727 *
28- * <p>{@link Aggregation} currently supports 3 types of basic aggregation:
28+ * <p>{@link Aggregation} currently supports 4 types of basic aggregation:
2929 *
3030 * <ul>
3131 * <li>Sum
3232 * <li>Count
3333 * <li>Distribution
34+ * <li>LastValue
3435 * </ul>
3536 *
3637 * <p>When creating a {@link View}, one {@link Aggregation} needs to be specified as how to
@@ -43,30 +44,16 @@ public abstract class Aggregation {
4344
4445 private Aggregation () {}
4546
46- /**
47- * Applies the given match function to the underlying data type.
48- *
49- * @since 0.8
50- * @deprecated in favor of {@link #match(Function, Function, Function, Function)}.
51- */
52- @ Deprecated
53- public abstract <T > T match (
54- Function <? super Sum , T > p0 ,
55- Function <? super Count , T > p1 ,
56- Function <? super Mean , T > p2 ,
57- Function <? super Distribution , T > p3 ,
58- Function <? super Aggregation , T > defaultFunction );
59-
6047 /**
6148 * Applies the given match function to the underlying data type.
6249 *
6350 * @since 0.13
6451 */
65- @ SuppressWarnings ("InconsistentOverloads" )
6652 public abstract <T > T match (
6753 Function <? super Sum , T > p0 ,
6854 Function <? super Count , T > p1 ,
6955 Function <? super Distribution , T > p2 ,
56+ Function <? super LastValue , T > p3 ,
7057 Function <? super Aggregation , T > defaultFunction );
7158
7259 /**
@@ -92,21 +79,12 @@ public static Sum create() {
9279 return INSTANCE ;
9380 }
9481
95- @ Override
96- public final <T > T match (
97- Function <? super Sum , T > p0 ,
98- Function <? super Count , T > p1 ,
99- Function <? super Mean , T > p2 ,
100- Function <? super Distribution , T > p3 ,
101- Function <? super Aggregation , T > defaultFunction ) {
102- return p0 .apply (this );
103- }
104-
10582 @ Override
10683 public final <T > T match (
10784 Function <? super Sum , T > p0 ,
10885 Function <? super Count , T > p1 ,
10986 Function <? super Distribution , T > p2 ,
87+ Function <? super LastValue , T > p3 ,
11088 Function <? super Aggregation , T > defaultFunction ) {
11189 return p0 .apply (this );
11290 }
@@ -135,21 +113,12 @@ public static Count create() {
135113 return INSTANCE ;
136114 }
137115
138- @ Override
139- public final <T > T match (
140- Function <? super Sum , T > p0 ,
141- Function <? super Count , T > p1 ,
142- Function <? super Mean , T > p2 ,
143- Function <? super Distribution , T > p3 ,
144- Function <? super Aggregation , T > defaultFunction ) {
145- return p1 .apply (this );
146- }
147-
148116 @ Override
149117 public final <T > T match (
150118 Function <? super Sum , T > p0 ,
151119 Function <? super Count , T > p1 ,
152120 Function <? super Distribution , T > p2 ,
121+ Function <? super LastValue , T > p3 ,
153122 Function <? super Aggregation , T > defaultFunction ) {
154123 return p1 .apply (this );
155124 }
@@ -181,21 +150,12 @@ public static Mean create() {
181150 return INSTANCE ;
182151 }
183152
184- @ Override
185- public final <T > T match (
186- Function <? super Sum , T > p0 ,
187- Function <? super Count , T > p1 ,
188- Function <? super Mean , T > p2 ,
189- Function <? super Distribution , T > p3 ,
190- Function <? super Aggregation , T > defaultFunction ) {
191- return p2 .apply (this );
192- }
193-
194153 @ Override
195154 public final <T > T match (
196155 Function <? super Sum , T > p0 ,
197156 Function <? super Count , T > p1 ,
198157 Function <? super Distribution , T > p2 ,
158+ Function <? super LastValue , T > p3 ,
199159 Function <? super Aggregation , T > defaultFunction ) {
200160 return defaultFunction .apply (this );
201161 }
@@ -236,19 +196,44 @@ public static Distribution create(BucketBoundaries bucketBoundaries) {
236196 public final <T > T match (
237197 Function <? super Sum , T > p0 ,
238198 Function <? super Count , T > p1 ,
239- Function <? super Mean , T > p2 ,
240- Function <? super Distribution , T > p3 ,
199+ Function <? super Distribution , T > p2 ,
200+ Function <? super LastValue , T > p3 ,
241201 Function <? super Aggregation , T > defaultFunction ) {
242- return p3 .apply (this );
202+ return p2 .apply (this );
203+ }
204+ }
205+
206+ /**
207+ * Calculate the last value of aggregated {@code MeasureValue}s.
208+ *
209+ * @since 0.13
210+ */
211+ @ Immutable
212+ @ AutoValue
213+ public abstract static class LastValue extends Aggregation {
214+
215+ LastValue () {}
216+
217+ private static final LastValue INSTANCE = new AutoValue_Aggregation_LastValue ();
218+
219+ /**
220+ * Construct a {@code LastValue}.
221+ *
222+ * @return a new {@code LastValue}.
223+ * @since 0.13
224+ */
225+ public static LastValue create () {
226+ return INSTANCE ;
243227 }
244228
245229 @ Override
246230 public final <T > T match (
247231 Function <? super Sum , T > p0 ,
248232 Function <? super Count , T > p1 ,
249233 Function <? super Distribution , T > p2 ,
234+ Function <? super LastValue , T > p3 ,
250235 Function <? super Aggregation , T > defaultFunction ) {
251- return p2 .apply (this );
236+ return p3 .apply (this );
252237 }
253238 }
254239}
0 commit comments