@Test public void findTopEntry() throws Exception { BasicHeuristic heuristic = new BasicHeuristic(); int threshold = BasicHeuristic.DEFAULT_THRESHOLD_EXCLUSIVE; String correctUrl = "http: HeuristicEntryMatcher.ParsedEntry[] entries = { createEntry("GET", "http: createEntry("GET", "http: createEntry("GET", correctUrl, 200, MediaType.PLAIN_TEXT_UTF_8, "good"), createEntry("POST", correctUrl, 200, MediaType.PLAIN_TEXT_UTF_8, "more bad"), createEntry("GET", "http: createEntry("GET", "http: }; HeuristicEntryMatcher<Object> matcher = new HeuristicEntryMatcher<>(heuristic, threshold, Arrays.asList(entries)); ParsedRequest request = Tests.createRequest("GET", correctUrl); Object state = new Object(); HttpRespondable response = matcher.findTopEntry(state, request); assertNotNull("response", response); assertEquals(200, response.getStatus()); assertEquals(1, response.streamHeaders().count()); String content = Tests.readAsString(response); assertEquals("content", "good", content); }
@Nullable @Override public HttpRespondable findTopEntry(S state, ParsedRequest request) { List<RatedEntry> ratedEntryList = entries.stream() .map(createEntryToRatingFunction(request, state)) .collect(Collectors.toList()); Optional<RatedEntry> topRatedEntry = ratedEntryList.stream() .filter(getRatedEntryFilter(state)) .max(getRatedEntryComparator()); if (topRatedEntry.isPresent()) { try { return topRatedEntry.get().entry.responseCreator.createRespondable(request); } catch (IOException e) { log.warn("could not create response for top-rated entry", e); } } return null; }
HeuristicEntryMatcher implements EntryMatcher<S> { @Nullable @Override public HttpRespondable findTopEntry(S state, ParsedRequest request) { List<RatedEntry> ratedEntryList = entries.stream() .map(createEntryToRatingFunction(request, state)) .collect(Collectors.toList()); Optional<RatedEntry> topRatedEntry = ratedEntryList.stream() .filter(getRatedEntryFilter(state)) .max(getRatedEntryComparator()); if (topRatedEntry.isPresent()) { try { return topRatedEntry.get().entry.responseCreator.createRespondable(request); } catch (IOException e) { log.warn("could not create response for top-rated entry", e); } } return null; } }
HeuristicEntryMatcher implements EntryMatcher<S> { @Nullable @Override public HttpRespondable findTopEntry(S state, ParsedRequest request) { List<RatedEntry> ratedEntryList = entries.stream() .map(createEntryToRatingFunction(request, state)) .collect(Collectors.toList()); Optional<RatedEntry> topRatedEntry = ratedEntryList.stream() .filter(getRatedEntryFilter(state)) .max(getRatedEntryComparator()); if (topRatedEntry.isPresent()) { try { return topRatedEntry.get().entry.responseCreator.createRespondable(request); } catch (IOException e) { log.warn("could not create response for top-rated entry", e); } } return null; } protected  HeuristicEntryMatcher(Heuristic heuristic, int thresholdExclusive, Collection<ParsedEntry> entries); }
HeuristicEntryMatcher implements EntryMatcher<S> { @Nullable @Override public HttpRespondable findTopEntry(S state, ParsedRequest request) { List<RatedEntry> ratedEntryList = entries.stream() .map(createEntryToRatingFunction(request, state)) .collect(Collectors.toList()); Optional<RatedEntry> topRatedEntry = ratedEntryList.stream() .filter(getRatedEntryFilter(state)) .max(getRatedEntryComparator()); if (topRatedEntry.isPresent()) { try { return topRatedEntry.get().entry.responseCreator.createRespondable(request); } catch (IOException e) { log.warn("could not create response for top-rated entry", e); } } return null; } protected  HeuristicEntryMatcher(Heuristic heuristic, int thresholdExclusive, Collection<ParsedEntry> entries); static EntryMatcherFactory<T> factory(Heuristic heuristic, int thresholdExclusive); @Nullable @Override HttpRespondable findTopEntry(S state, ParsedRequest request); }
HeuristicEntryMatcher implements EntryMatcher<S> { @Nullable @Override public HttpRespondable findTopEntry(S state, ParsedRequest request) { List<RatedEntry> ratedEntryList = entries.stream() .map(createEntryToRatingFunction(request, state)) .collect(Collectors.toList()); Optional<RatedEntry> topRatedEntry = ratedEntryList.stream() .filter(getRatedEntryFilter(state)) .max(getRatedEntryComparator()); if (topRatedEntry.isPresent()) { try { return topRatedEntry.get().entry.responseCreator.createRespondable(request); } catch (IOException e) { log.warn("could not create response for top-rated entry", e); } } return null; } protected  HeuristicEntryMatcher(Heuristic heuristic, int thresholdExclusive, Collection<ParsedEntry> entries); static EntryMatcherFactory<T> factory(Heuristic heuristic, int thresholdExclusive); @Nullable @Override HttpRespondable findTopEntry(S state, ParsedRequest request);  }