Skip to content

Commit 2c709d3

Browse files
committed
Removed lambdas in ValuesSourceRegistry
1 parent 4033b98 commit 2c709d3

1 file changed

Lines changed: 21 additions & 39 deletions

File tree

server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceRegistry.java

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.HashMap;
3333
import java.util.List;
3434
import java.util.Map;
35-
import java.util.function.Predicate;
3635

3736
/**
3837
* {@link ValuesSourceRegistry} holds the mapping from {@link ValuesSourceType}s to {@link AggregatorSupplier}s. DO NOT directly
@@ -42,55 +41,38 @@
4241
*/
4342
public class ValuesSourceRegistry {
4443
public static class Builder {
45-
private Map<String, List<Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier>>> aggregatorRegistry = new HashMap<>();
44+
private Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry = new HashMap<>();
45+
4646
/**
47-
* Register a ValuesSource to Aggregator mapping.
48-
*
47+
* Register a ValuesSource to Aggregator mapping. This method registers mappings that only apply to a
48+
* single {@link ValuesSourceType}
4949
* @param aggregationName The name of the family of aggregations, typically found via
5050
* {@link ValuesSourceAggregationBuilder#getType()}
51-
* @param appliesTo A predicate which accepts the resolved {@link ValuesSourceType} and decides if the given aggregator can be
52-
* applied to that type.
51+
* @param valuesSourceType The ValuesSourceType this mapping applies to.
5352
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator
53+
* from the aggregation standard set of parameters
5454
*/
55-
private void register(String aggregationName, Predicate<ValuesSourceType> appliesTo,
55+
public void register(String aggregationName, ValuesSourceType valuesSourceType,
5656
AggregatorSupplier aggregatorSupplier) {
5757
if (aggregatorRegistry.containsKey(aggregationName) == false) {
5858
aggregatorRegistry.put(aggregationName, new ArrayList<>());
5959
}
60-
aggregatorRegistry.get(aggregationName).add( new AbstractMap.SimpleEntry<>(appliesTo, aggregatorSupplier));
61-
}
62-
63-
/**
64-
* Register a ValuesSource to Aggregator mapping. This version provides a convenience method for mappings that only apply to a
65-
* single {@link ValuesSourceType}, to allow passing in the type and auto-wrapping it in a predicate
66-
* @param aggregationName The name of the family of aggregations, typically found via
67-
* {@link ValuesSourceAggregationBuilder#getType()}
68-
* @param valuesSourceType The ValuesSourceType this mapping applies to.
69-
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator
70-
* from the aggregation standard set of parameters
71-
*/
72-
public void register(String aggregationName, ValuesSourceType valuesSourceType, AggregatorSupplier aggregatorSupplier) {
73-
register(aggregationName, (candidate) -> valuesSourceType.equals(candidate), aggregatorSupplier);
60+
aggregatorRegistry.get(aggregationName).add(new AbstractMap.SimpleEntry<>(valuesSourceType, aggregatorSupplier));
7461
}
7562

7663
/**
77-
* Register a ValuesSource to Aggregator mapping. This version provides a convenience method for mappings that only apply to a
78-
* known list of {@link ValuesSourceType}, to allow passing in the type and auto-wrapping it in a predicate
64+
* Register a ValuesSource to Aggregator mapping. This version provides a convenience method for mappings that apply to a
65+
* known list of {@link ValuesSourceType}
7966
* @param aggregationName The name of the family of aggregations, typically found via
8067
* {@link ValuesSourceAggregationBuilder#getType()}
8168
* @param valuesSourceTypes The ValuesSourceTypes this mapping applies to.
8269
* @param aggregatorSupplier An Aggregation-specific specialization of AggregatorSupplier which will construct the mapped aggregator
8370
* from the aggregation standard set of parameters
8471
*/
8572
public void register(String aggregationName, List<ValuesSourceType> valuesSourceTypes, AggregatorSupplier aggregatorSupplier) {
86-
register(aggregationName, (candidate) -> {
87-
for (ValuesSourceType valuesSourceType : valuesSourceTypes) {
88-
if (valuesSourceType.equals(candidate)) {
89-
return true;
90-
}
91-
}
92-
return false;
93-
}, aggregatorSupplier);
73+
for (ValuesSourceType valuesSourceType : valuesSourceTypes) {
74+
register(aggregationName, valuesSourceType, aggregatorSupplier);
75+
}
9476
}
9577

9678
public ValuesSourceRegistry build() {
@@ -99,27 +81,27 @@ public ValuesSourceRegistry build() {
9981
}
10082

10183
/** Maps Aggregation names to (ValuesSourceType, Supplier) pairs, keyed by ValuesSourceType */
102-
private Map<String, List<Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier>>> aggregatorRegistry;
103-
public ValuesSourceRegistry(Map<String, List<Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier>>> aggregatorRegistry) {
84+
private Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry;
85+
public ValuesSourceRegistry(Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry) {
10486
/*
105-
Make an immutatble copy of our input map. Since this is write once, read many, we'll spend a bit of extra time to shape this
87+
Make an immutatble copy of our input map. Since this is write once, read many, we'll spend a bit of extra time to shape this
10688
into a Map.of(), which is more read optimized than just using a hash map.
10789
*/
10890
Map.Entry[] copiedEntries = new Map.Entry[aggregatorRegistry.size()];
10991
int i = 0;
110-
for (Map.Entry<String, List<Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier>>> entry : aggregatorRegistry.entrySet()) {
92+
for (Map.Entry<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> entry : aggregatorRegistry.entrySet()) {
11193
String aggName = entry.getKey();
112-
List<Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier>> values = entry.getValue();
94+
List<Map.Entry<ValuesSourceType, AggregatorSupplier>> values = entry.getValue();
11395
Map.Entry newEntry = Map.entry(aggName, List.of(values.toArray()));
11496
copiedEntries[i++] = newEntry;
11597
}
11698
this.aggregatorRegistry = Map.ofEntries(copiedEntries);
11799
}
118100

119101
private AggregatorSupplier findMatchingSuppier(ValuesSourceType valuesSourceType,
120-
List<Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier>> supportedTypes) {
121-
for (Map.Entry<Predicate<ValuesSourceType>, AggregatorSupplier> candidate : supportedTypes) {
122-
if (candidate.getKey().test(valuesSourceType)) {
102+
List<Map.Entry<ValuesSourceType, AggregatorSupplier>> supportedTypes) {
103+
for (Map.Entry<ValuesSourceType, AggregatorSupplier> candidate : supportedTypes) {
104+
if (candidate.getKey().equals(valuesSourceType)) {
123105
return candidate.getValue();
124106
}
125107
}

0 commit comments

Comments
 (0)