@Test public void test() throws Exception { final HostResolver resolver = new HostResolver(ALL_HOSTS, new Name[]{}); assertEquals("host1.bar.com", resolver.resolveName("host1.bar.com")); assertEquals("whee.bar.com", resolver.resolveName("whee.bar.com")); assertEquals("host1.bar.com", resolver.resolveName("host1.bar")); assertEquals("host1.bar.com", resolver.resolveName("host1.b")); assertEquals("host1", resolver.resolveName("host1")); }
String resolveName(final String host) { if (allHosts.contains(host)) { return host; } final List<String> matches = findPrefixMatches(host); if (matches.isEmpty()) { return host; } if (matches.size() == 1) { return matches.iterator().next(); } final List<ScoredHost> scored = scoreMatches(matches); final List<ScoredHost> sorted = sortScoredHosts(scored); final List<String> minScoreHosts = findMatchesWithLowestScore(sorted); if (minScoreHosts.size() > 1) { return host; } return minScoreHosts.get(0); }
HostResolver { String resolveName(final String host) { if (allHosts.contains(host)) { return host; } final List<String> matches = findPrefixMatches(host); if (matches.isEmpty()) { return host; } if (matches.size() == 1) { return matches.iterator().next(); } final List<ScoredHost> scored = scoreMatches(matches); final List<ScoredHost> sorted = sortScoredHosts(scored); final List<String> minScoreHosts = findMatchesWithLowestScore(sorted); if (minScoreHosts.size() > 1) { return host; } return minScoreHosts.get(0); } }
HostResolver { String resolveName(final String host) { if (allHosts.contains(host)) { return host; } final List<String> matches = findPrefixMatches(host); if (matches.isEmpty()) { return host; } if (matches.size() == 1) { return matches.iterator().next(); } final List<ScoredHost> scored = scoreMatches(matches); final List<ScoredHost> sorted = sortScoredHosts(scored); final List<String> minScoreHosts = findMatchesWithLowestScore(sorted); if (minScoreHosts.size() > 1) { return host; } return minScoreHosts.get(0); } HostResolver(final Set<String> allHosts,
               final Name[] searchPath); }
HostResolver { String resolveName(final String host) { if (allHosts.contains(host)) { return host; } final List<String> matches = findPrefixMatches(host); if (matches.isEmpty()) { return host; } if (matches.size() == 1) { return matches.iterator().next(); } final List<ScoredHost> scored = scoreMatches(matches); final List<ScoredHost> sorted = sortScoredHosts(scored); final List<String> minScoreHosts = findMatchesWithLowestScore(sorted); if (minScoreHosts.size() > 1) { return host; } return minScoreHosts.get(0); } HostResolver(final Set<String> allHosts,
               final Name[] searchPath); List<String> getSortedMatches(final String hostName); }
HostResolver { String resolveName(final String host) { if (allHosts.contains(host)) { return host; } final List<String> matches = findPrefixMatches(host); if (matches.isEmpty()) { return host; } if (matches.size() == 1) { return matches.iterator().next(); } final List<ScoredHost> scored = scoreMatches(matches); final List<ScoredHost> sorted = sortScoredHosts(scored); final List<String> minScoreHosts = findMatchesWithLowestScore(sorted); if (minScoreHosts.size() > 1) { return host; } return minScoreHosts.get(0); } HostResolver(final Set<String> allHosts,
               final Name[] searchPath); List<String> getSortedMatches(final String hostName);  }