-
Notifications
You must be signed in to change notification settings - Fork 22
/
Aggregation.cls
64 lines (51 loc) · 1.7 KB
/
Aggregation.cls
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
public class Aggregation {
private enum Operation {
COUNT,
COUNT_DISTINCT,
SUM,
AVERAGE,
MAX,
MIN
}
private final Operation op;
private final String fieldName;
private final String alias;
private Aggregation(Operation op, Schema.SObjectField fieldToken, String alias) {
this.op = op;
this.fieldName = fieldToken.getDescribe().getName();
this.alias = alias;
}
public static Aggregation sum(Schema.SObjectField fieldToken, String alias) {
return new Aggregation(Operation.SUM, fieldToken, alias);
}
public static Aggregation count(Schema.SObjectField fieldToken, String alias) {
return new Aggregation(Operation.COUNT, fieldToken, alias);
}
public static Aggregation countDistinct(Schema.SObjectfield fieldToken, String alias) {
return new Aggregation(Operation.COUNT_DISTINCT, fieldToken, alias);
}
public static Aggregation average(Schema.SObjectfield fieldToken, String alias) {
return new Aggregation(Operation.AVERAGE, fieldToken, alias);
}
public static Aggregation max(Schema.SObjectfield fieldToken, String alias) {
return new Aggregation(Operation.MAX, fieldToken, alias);
}
public static Aggregation min(Schema.SObjectfield fieldToken, String alias) {
return new Aggregation(Operation.MIN, fieldToken, alias);
}
public String getAlias() {
return this.alias;
}
public String getFieldName() {
return this.fieldName;
}
public String getBaseAggregation() {
return this.op.name() + '(' + fieldName + ')';
}
public override String toString() {
return this.getBaseAggregation() + ' ' + this.alias;
}
public Boolean equals(Object that) {
return this.toString() == that.toString();
}
}