class DecoderUtils {

    public static List<CandidateLinePair> resolveCandidatesOrder(
            final LocationReferencePoint p1, final LocationReferencePoint p2,
            final CandidateLinesResultSet candidateLines,
            final CandidateLine lastUsed,
            final OpenLRDecoderProperties properties, final LocationType locType)
            throws OpenLRProcessingException {
        if (LOG.isDebugEnabled()) {
            LOG.debug("resolve candidates order with ConnectedRouteIncrease: "
                    + properties.getConnectedRouteIncrease()
                    + " and MaxNrRetries: " + properties.getMaxNumberRetries());
        }
        List<CandidateLinePair> pairs = new ArrayList<CandidateLinePair>();
        List<CandidateLine> p1List = candidateLines.getCandidateLines(p1);
        List<CandidateLine> p2List = candidateLines.getCandidateLines(p2);
        for (int i = 0; i < p1List.size(); ++i) {
            int p1Score = p1List.get(i).getRating();
            CandidateLine cl = p1List.get(i);
            // check connection with previously calculated path
            if (lastUsed != null && cl.hasSameLine(lastUsed)) {
                p1Score += (properties.getConnectedRouteIncrease() * p1Score);
            }
            for (int j = 0; j < p2List.size(); ++j) {
                int p2Score = p2List.get(j).getRating();
                CandidateLinePair candidate = new CandidateLinePair(i, j,
                        p1Score * p2Score);
                pairs.add(candidate);
            }
        }
        Collections.sort(pairs,
                new CandidateLinePair.CandidateLinePairComparator());
        int returnSize = Math.min(properties.getMaxNumberRetries() + 1,
                pairs.size());
        List<CandidateLinePair> subList = pairs.subList(0, returnSize);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Candidate pair list for " + p1.getSequenceNumber()
                    + " and " + p2.getSequenceNumber());
            for (CandidateLinePair clp : subList) {
                LOG.debug("startIdx[" + clp.getStartIndex() + "] - destIdx["
                        + clp.getDestIndex() + "], score: " + clp.getScore());
            }
        }
        return subList;
    }

    private  DecoderUtils();

}