in spectator-api/src/main/java/com/netflix/spectator/impl/matcher/PatternUtils.java [223:257]
static List<Matcher> expandOrClauses(Matcher matcher, int max) {
if (matcher instanceof IndexOfMatcher) {
IndexOfMatcher m = matcher.as();
return map(expandOrClauses(m.next(), max), n -> new IndexOfMatcher(m.pattern(), n), max);
} else if (matcher instanceof ZeroOrMoreMatcher) {
ZeroOrMoreMatcher m = matcher.as();
return map(expandOrClauses(m.next(), max), n -> new ZeroOrMoreMatcher(m.repeated(), n), max);
} else if (matcher instanceof ZeroOrOneMatcher) {
ZeroOrOneMatcher m = matcher.as();
List<Matcher> rs = expandOrClauses(m.repeated(), max);
List<Matcher> ns = expandOrClauses(m.next(), max);
if (rs == null || ns == null || ns.size() * (rs.size() + 1) > max) {
return null;
} else if (rs.size() == 1 && ns.size() == 1) {
return Collections.singletonList(matcher);
} else {
List<Matcher> results = new ArrayList<>(ns);
for (Matcher r : rs) {
for (Matcher n : ns) {
results.add(new ZeroOrOneMatcher(r, n));
}
}
return results;
}
} else if (matcher instanceof PositiveLookaheadMatcher) {
PositiveLookaheadMatcher m = matcher.as();
return map(expandOrClauses(m.matcher(), max), PositiveLookaheadMatcher::new, max);
} else if (matcher instanceof SeqMatcher) {
return expandSeq(matcher.as(), max);
} else if (matcher instanceof OrMatcher) {
return expandOr(matcher.as(), max);
} else {
return Collections.singletonList(matcher);
}
}