### Question:
Optimizer { static Matcher flattenNestedOr(Matcher matcher) { if (matcher instanceof OrMatcher) { List<Matcher> matchers = matcher.<OrMatcher>as().matchers(); List<Matcher> ms = new ArrayList<>(); for (Matcher m : matchers) { if (m instanceof OrMatcher) { ms.addAll(m.<OrMatcher>as().matchers()); } else { ms.add(m); } } return OrMatcher.create(ms); } return matcher; } private  Optimizer();   }### Answer:
@Test public void flattenNestedOr() { Matcher input = OrMatcher.create( OrMatcher.create(AnyMatcher.INSTANCE, AnyMatcher.INSTANCE), AnyMatcher.INSTANCE, OrMatcher.create(AnyMatcher.INSTANCE, OrMatcher.create(AnyMatcher.INSTANCE)) ); Matcher expected = OrMatcher.create( AnyMatcher.INSTANCE, AnyMatcher.INSTANCE, AnyMatcher.INSTANCE, AnyMatcher.INSTANCE, AnyMatcher.INSTANCE ); Assertions.assertEquals(expected, Optimizer.flattenNestedOr(input)); }