Use an enhanced switch to ensure all branches are covered.
@@ -97,17 +97,12 @@ public class Dispatcher extends AbstractComponent {
}
private static LoadBalancer.Policy toLoadBalancerPolicy(DispatchConfig.DistributionPolicy.Enum policy) {
- if (policy == DispatchConfig.DistributionPolicy.ROUNDROBIN) {
- return LoadBalancer.Policy.ROUNDROBIN;
- } else if (policy == DispatchConfig.DistributionPolicy.BEST_OF_RANDOM_2) {
- return LoadBalancer.Policy.BEST_OF_RANDOM_2;
- } else if (policy == DispatchConfig.DistributionPolicy.LATENCY_AMORTIZED_OVER_REQUESTS) {
- return LoadBalancer.Policy.LATENCY_AMORTIZED_OVER_REQUESTS;
- } else if (policy == DispatchConfig.DistributionPolicy.LATENCY_AMORTIZED_OVER_TIME) {
- return LoadBalancer.Policy.LATENCY_AMORTIZED_OVER_TIME;
- } else {
- return LoadBalancer.Policy.LATENCY_AMORTIZED_OVER_REQUESTS;
- }
+ return switch (policy) {
+ case ROUNDROBIN: yield LoadBalancer.Policy.ROUNDROBIN;
+ case BEST_OF_RANDOM_2: yield LoadBalancer.Policy.BEST_OF_RANDOM_2;
+ case ADAPTIVE,LATENCY_AMORTIZED_OVER_REQUESTS: yield LoadBalancer.Policy.LATENCY_AMORTIZED_OVER_REQUESTS;
+ case LATENCY_AMORTIZED_OVER_TIME: yield LoadBalancer.Policy.LATENCY_AMORTIZED_OVER_TIME;
+ };
}
/* Protected for simple mocking in tests. Beware that searchCluster is shutdown on in deconstruct() */
