boolean (RegExpElement[] elements1, RegExpElement[] elements2, boolean inAnyOrder) { if (elements1.length != elements2.length) { return false; } if (inAnyOrder) { Arrays.sort(elements1, TEXT_COMPARATOR); Arrays.sort(elements2, TEXT_COMPARATOR); } return ArrayUtil.areEqual(elements1, elements2, RegExpEquivalenceChecker::areElementsEquivalent); }