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;
  }
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 ; }
Nested OR clauses can be simplified to a just a simple set of options. For example,
{@code "(a|b|(c|d|(e|f))|g)" => "a|b|c|d|e|f|g"}.