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); 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(); static List<CandidateLinePair> resolveCandidatesOrder(
            final LocationReferencePoint p1, final LocationReferencePoint p2,
            final CandidateLinesResultSet candidateLines,
            final CandidateLine lastUsed,
            final OpenLRDecoderProperties properties, final LocationType locType); static int determineRouteLength(final RouteSearch rs,
                                           final CandidateLine destCandidate); static int calculateMaxLength(final LocationReferencePoint p,
                                         final CandidateLine candP, final CandidateLine candNext,
                                         final OpenLRDecoderProperties properties); static int getMaxDistanceNP(final LocationReferencePoint lrp,
                                       final OpenLRDecoderProperties properties); static int getMinDistanceNP(final LocationReferencePoint lrp,
                                       final OpenLRDecoderProperties properties);  }
@Test public void testCandidatePairOrder() { final Line l24 = context.mock(Line.class, "l24"); context.checking(new Expectations() { { allowing(l24).getID(); will(returnValue(24l)); } }); final Line l21 = context.mock(Line.class, "l21"); context.checking(new Expectations() { { allowing(l21).getID(); will(returnValue(21l)); } }); final Line l33 = context.mock(Line.class, "l33"); context.checking(new Expectations() { { allowing(l33).getID(); will(returnValue(33l)); } }); final LocationReferencePoint lrp1 = context .mock(LocationReferencePoint.class, "lrp1"); context.checking(new Expectations() { { allowing(lrp1).getSequenceNumber(); will(returnValue(1)); } }); List<CandidateLine> candidates1 = new ArrayList<CandidateLine>(); candidates1.add(new CandidateLine(l24, 1197)); candidates1.add(new CandidateLine(l21, 1110)); candidates1.add(new CandidateLine(l33, 855)); CandidateLinesResultSet clrs = new CandidateLinesResultSet(); clrs.putCandidateLines(lrp1, candidates1); final LocationReferencePoint lrp2 = context .mock(LocationReferencePoint.class, "lrp2"); context.checking(new Expectations() { { allowing(lrp2).getSequenceNumber(); will(returnValue(2)); } }); context.checking(new Expectations() { { allowing(lrp2).isLastLRP(); will(returnValue(false)); } }); List<CandidateLine> candidates2 = new ArrayList<CandidateLine>(); candidates2.add(new CandidateLine(l24, 1164)); candidates2.add(new CandidateLine(l21, 1149)); candidates2.add(new CandidateLine(l33, 821)); clrs.putCandidateLines(lrp2, candidates2); final LocationReferencePoint lrp3 = context .mock(LocationReferencePoint.class, "lrp3"); context.checking(new Expectations() { { allowing(lrp3).getSequenceNumber(); will(returnValue(3)); } }); context.checking(new Expectations() { { allowing(lrp3).isLastLRP(); will(returnValue(true)); } }); List<CandidateLine> candidates3 = new ArrayList<CandidateLine>(); candidates3.add(new CandidateLine(l24, 1194)); candidates3.add(new CandidateLine(l33, 821)); clrs.putCandidateLines(lrp3, candidates3); try { List<CandidateLinePair> order = DecoderUtils .resolveCandidatesOrder(lrp1, lrp2, clrs, null, new OpenLRDecoderProperties(null), LocationType.LINE_LOCATION); } catch (OpenLRProcessingException e) { e.printStackTrace(); Assert.fail("Unexpected exception"); } }