[7.x] Simplify the ValuesSourceRegistry structure (#56154) (#56197)

Follow up to #55747.
This commit is contained in:
Igor Motov 2020-05-05 10:37:02 -04:00 committed by GitHub
parent fd91617b19
commit 94b349cd18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 10 deletions

View File

@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* {@link ValuesSourceRegistry} holds the mapping from {@link ValuesSourceType}s to {@link AggregatorSupplier}s. DO NOT directly * {@link ValuesSourceRegistry} holds the mapping from {@link ValuesSourceType}s to {@link AggregatorSupplier}s. DO NOT directly
@ -99,24 +100,20 @@ public class ValuesSourceRegistry {
/** Maps Aggregation names to (ValuesSourceType, Supplier) pairs, keyed by ValuesSourceType */ /** Maps Aggregation names to (ValuesSourceType, Supplier) pairs, keyed by ValuesSourceType */
private final AggregationUsageService usageService; private final AggregationUsageService usageService;
private Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry; private final Map<String, Map<ValuesSourceType, AggregatorSupplier>> aggregatorRegistry;
public ValuesSourceRegistry(Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry, public ValuesSourceRegistry(Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> aggregatorRegistry,
AggregationUsageService usageService) { AggregationUsageService usageService) {
Map<String, List<Map.Entry<ValuesSourceType, AggregatorSupplier>>> tmp = new HashMap<>(); Map<String, Map<ValuesSourceType, AggregatorSupplier>> tmp = new HashMap<>();
aggregatorRegistry.forEach((key, value) -> tmp.put(key, Collections.unmodifiableList(value))); aggregatorRegistry.forEach((key, value) -> tmp.put(key, value.stream().collect(
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))));
this.aggregatorRegistry = Collections.unmodifiableMap(tmp); this.aggregatorRegistry = Collections.unmodifiableMap(tmp);
this.usageService = usageService; this.usageService = usageService;
} }
private AggregatorSupplier findMatchingSuppier(ValuesSourceType valuesSourceType, private AggregatorSupplier findMatchingSuppier(ValuesSourceType valuesSourceType,
List<Map.Entry<ValuesSourceType, AggregatorSupplier>> supportedTypes) { Map<ValuesSourceType, AggregatorSupplier> supportedTypes) {
for (Map.Entry<ValuesSourceType, AggregatorSupplier> candidate : supportedTypes) { return supportedTypes.get(valuesSourceType);
if (candidate.getKey().equals(valuesSourceType)) {
return candidate.getValue();
}
}
return null;
} }
public AggregatorSupplier getAggregator(ValuesSourceType valuesSourceType, String aggregationName) { public AggregatorSupplier getAggregator(ValuesSourceType valuesSourceType, String aggregationName) {