### Question:
Optimizer { static Matcher combineAdjacentCharSeqs(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); List<Matcher> ms = new ArrayList<>(); CharSeqMatcher cs1 = null; for (Matcher m : matchers) { if (m instanceof CharSeqMatcher) { if (cs1 == null) { cs1 = m.as(); } else { CharSeqMatcher cs2 = m.as(); cs1 = new CharSeqMatcher(cs1.pattern() + cs2.pattern()); } } else { if (cs1 != null) { ms.add(cs1); cs1 = null; } ms.add(m); } } if (cs1 != null) { ms.add(cs1); } return SeqMatcher.create(ms); } return matcher; } private  Optimizer();   }### Answer:
@Test public void combineAdjacentCharSeqs() { Matcher input = SeqMatcher.create( new CharSeqMatcher("a"), new CharSeqMatcher("b"), AnyMatcher.INSTANCE, new CharSeqMatcher("c"), new CharSeqMatcher("d") ); Matcher expected = SeqMatcher.create( new CharSeqMatcher("ab"), AnyMatcher.INSTANCE, new CharSeqMatcher("cd") ); Assertions.assertEquals(expected, Optimizer.combineAdjacentCharSeqs(input)); }