AbstractFilePatchInProgress () { AbstractFilePatchInProgress best = null; int bestLines = Integer.MIN_VALUE; boolean bestIsUnique = true; AbstractFilePatchInProgress baseDirVariant = null; for (AbstractFilePatchInProgress variant : myVariants) { TextFilePatchInProgress current = (TextFilePatchInProgress)variant; final int currentLines = getMatchingLines(current); if (best == null || isBetterMatch(current, currentLines, best, bestLines)) { bestLines = currentLines; best = current; bestIsUnique = true; } else if (!isBetterMatch(best, bestLines, current, currentLines)) { bestIsUnique = false; } if (baseDirVariant == null && myBaseDir.equals(current.getBase())) { baseDirVariant = current; } } if (!bestIsUnique && baseDirVariant != null) { return baseDirVariant; } return best; }