Skip to content

Commit 7cad139

Browse files
committed
use switch in PredicateEvaluator
1 parent 3b6129f commit 7cad139

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

xds/src/main/java/io/grpc/xds/internal/matcher/PredicateEvaluator.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ abstract class PredicateEvaluator {
2828
abstract boolean evaluate(MatchContext context);
2929

3030
static PredicateEvaluator fromProto(Predicate proto) {
31-
if (proto.hasSinglePredicate()) {
32-
return new SinglePredicateEvaluator(proto.getSinglePredicate());
33-
} else if (proto.hasOrMatcher()) {
34-
return new OrMatcherEvaluator(proto.getOrMatcher());
35-
} else if (proto.hasAndMatcher()) {
36-
return new AndMatcherEvaluator(proto.getAndMatcher());
37-
} else if (proto.hasNotMatcher()) {
38-
return new NotMatcherEvaluator(proto.getNotMatcher());
31+
switch (proto.getMatchTypeCase()) {
32+
case SINGLE_PREDICATE:
33+
return new SinglePredicateEvaluator(proto.getSinglePredicate());
34+
case OR_MATCHER:
35+
return new OrMatcherEvaluator(proto.getOrMatcher());
36+
case AND_MATCHER:
37+
return new AndMatcherEvaluator(proto.getAndMatcher());
38+
case NOT_MATCHER:
39+
return new NotMatcherEvaluator(proto.getNotMatcher());
40+
case MATCHTYPE_NOT_SET:
41+
default:
42+
throw new IllegalArgumentException(
43+
"Predicate must have one of: single_predicate, or_matcher, and_matcher, not_matcher");
3944
}
40-
throw new IllegalArgumentException(
41-
"Predicate must have one of: single_predicate, or_matcher, and_matcher, not_matcher");
4245
}
4346

4447
private static final class SinglePredicateEvaluator extends PredicateEvaluator {

0 commit comments

Comments
 (0)