AuthoritativeSourceResolver { static Optional<AuthoritativeRatingVantagePoint> getMostSpecificRanked(Collection<AuthoritativeRatingVantagePoint> vantagePoints) { Comparator<AuthoritativeRatingVantagePoint> comparator = Comparator .comparingInt(AuthoritativeRatingVantagePoint::vantagePointRank) .thenComparingInt(AuthoritativeRatingVantagePoint::dataTypeRank); return head( sort( vantagePoints, (x, y) -> comparator.compare(y, x))); } AuthoritativeSourceResolver(List<AuthoritativeRatingVantagePoint> authoritativeRatingVantagePoints); AuthoritativenessRating resolve(EntityReference vantagePoint, EntityReference source, String dataTypeCode);  }
@Test public void getBestRankedIsCorrect() { ImmutableAuthoritativeRatingVantagePoint rank12 = ImmutableAuthoritativeRatingVantagePoint.builder() .vantagePoint(vantagePoint) .vantagePointRank(1) .dataTypeCode("REF_DATA") .dataType(EntityReference.mkRef(EntityKind.DATA_TYPE, 20)) .dataTypeRank(2) .applicationId(205L) .rating(AuthoritativenessRating.PRIMARY) .build(); ImmutableAuthoritativeRatingVantagePoint rank22 = rank12.withVantagePointRank(2); ImmutableAuthoritativeRatingVantagePoint rank11 = rank12.withDataTypeRank(1); Optional<AuthoritativeRatingVantagePoint> bestRankedOrgUnit = AuthoritativeSourceResolver.getMostSpecificRanked(ListUtilities.newArrayList(rank12, rank22)); Optional<AuthoritativeRatingVantagePoint> bestRankedDataType = AuthoritativeSourceResolver.getMostSpecificRanked(ListUtilities.newArrayList(rank12, rank11)); Assert.assertTrue(bestRankedOrgUnit.isPresent()); Assert.assertEquals(rank22, bestRankedOrgUnit.get()); Assert.assertTrue(bestRankedDataType.isPresent()); Assert.assertEquals(rank12, bestRankedDataType.get()); }
@Test public void getBestRankedWorksWithEmpty() { Optional<AuthoritativeRatingVantagePoint> bestRanked = AuthoritativeSourceResolver.getMostSpecificRanked(ListUtilities.newArrayList()); Assert.assertFalse(bestRanked.isPresent()); }