Slightly optimize SimpleMetaValueSelector by only invoking the selection strategy if there is a selection to be made

This commit is contained in:
Luck 2020-04-16 14:50:44 +01:00
parent 4d7a6cb658
commit 37e09caac5
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -43,7 +43,14 @@ public class SimpleMetaValueSelector implements MetaValueSelector {
@Override
public @NonNull String selectValue(@NonNull String key, @NonNull List<String> values) {
return this.strategies.getOrDefault(key, this.defaultStrategy).select(values);
switch (values.size()) {
case 0:
throw new IllegalArgumentException("values is empty");
case 1:
return values.get(0);
default:
return this.strategies.getOrDefault(key, this.defaultStrategy).select(values);
}
}
public enum Strategy {