/** * Returns {@code CandidateCompareResult#THIS} if this candidate is better, {@code CandidateCompareResult#OTHER} if the * right candidate was better, {@code CandidateCompareResult#AMBIGUOUS} if both candidates are valid * but ambiguous or {@code CandidateCompareResult#EQUALLY_INVALID} if both candidates are * ambiguous but erroneous. * @see #compareTo(AbstractPendingLinkingCandidate, boolean) */ protected final CandidateCompareResult compareTo(AbstractPendingLinkingCandidate<?> right) { return compareTo(right, false); }
protected CandidateCompareResult compareTo(AbstractPendingLinkingCandidate<?> right) { Candidate primaryCandidate = getPrimaryCandidate(); CandidateCompareResult result = primaryCandidate.compareTo(right); return result; }
@SuppressWarnings("incomplete-switch") @Override protected CandidateCompareResult compareTo(AbstractPendingLinkingCandidate<?> right, boolean invalid) { CandidateCompareResult compareResult = compareByAssignmentName(right); switch(compareResult) { case SUSPICIOUS_OTHER: throw new IllegalStateException(); case EQUALLY_INVALID: invalid = true; break; case OTHER: case THIS: return compareResult; } return super.compareTo(right, invalid); }
/** * Returns the best candidate considering the this and the given other candidate. * * The result is not necessarily this or the other, but may also be a third instance, * e.g. in order to disambiguate certain error conditions. */ @Override public ILinkingCandidate getPreferredCandidate(ILinkingCandidate other) { if (other instanceof AbstractPendingLinkingCandidate) { AbstractPendingLinkingCandidate<?> right = (AbstractPendingLinkingCandidate<?>) other; CandidateCompareResult candidateCompareResult = compareTo(right); switch(candidateCompareResult) { case AMBIGUOUS: return createAmbiguousLinkingCandidate(right); case SUSPICIOUS_OTHER: return createSuspiciousLinkingCandidate(right); case EQUALLY_INVALID: case THIS: return this; case OTHER: return other; } } throw new IllegalArgumentException("other was " + other); }