/
MaxAggregator.ts
48 lines (45 loc) · 1.16 KB
/
MaxAggregator.ts
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { OrderByDocumentProducerComparator } from "../orderByDocumentProducerComparator";
import { Aggregator } from "./Aggregator";
interface MaxAggregateResult {
count: number;
max?: number;
}
/** @hidden */
export class MaxAggregator implements Aggregator {
private value: number;
private comparer: OrderByDocumentProducerComparator;
/**
* Represents an aggregator for MAX operator.
* @constructor MaxAggregator
* @ignore
*/
constructor() {
this.value = undefined;
this.comparer = new OrderByDocumentProducerComparator(["Ascending"]);
}
/**
* Add the provided item to aggregation result.
* @memberof MaxAggregator
* @instance
* @param other
*/
public aggregate(other: MaxAggregateResult) {
if (this.value === undefined) {
this.value = other.max;
} else if (
this.comparer.compareValue(other.max, typeof other.max, this.value, typeof this.value) > 0
) {
this.value = other.max;
}
}
/**
* Get the aggregation result.
* @memberof MaxAggregator
* @instance
*/
public getResult() {
return this.value;
}
}