Comparator<MatchResult> () { return (mr1, mr2) -> { boolean exactPrefix1 = StringUtil.startsWith(mr1.elementName, patternSuffix); boolean exactPrefix2 = StringUtil.startsWith(mr2.elementName, patternSuffix); if (exactPrefix1 && exactPrefix2) return 0; if (exactPrefix1 != exactPrefix2) return exactPrefix1 ? -1 : 1; return mr1.compareDegrees(mr2); }; }