Match (PsiCaseLabelElement @Nullable [] labelElements1, PsiCaseLabelElement @Nullable [] labelElements2, boolean inAnyOrder) { if (labelElements1 == null || labelElements2 == null) { return Match.exact(labelElements1 == labelElements2); } if (labelElements1.length != labelElements2.length) { return EXACT_MISMATCH; } if (inAnyOrder) { Arrays.sort(labelElements1, LABEL_ELEMENT_COMPARATOR); Arrays.sort(labelElements2, LABEL_ELEMENT_COMPARATOR); } Match incompleteMatch = null; for (int i = 0; i < labelElements1.length; i++) { final Match match = labelElementsMatch(labelElements1[i], labelElements2[i]); if (incompleteMatch == null && match.isPartialMatch()) { incompleteMatch = match; } else if (!match.isExactMatch()) { if (incompleteMatch != null) { return EXACT_MISMATCH; } incompleteMatch = match.partialIfExactMismatch(labelElements1[i], labelElements2[i]); } } return incompleteMatch == null ? EXACT_MATCH : incompleteMatch; }