/** * @param entries The entries - ignored if {@code null}/empty * @return A {@link HostConfigEntryResolver} wrapper using the entries */ public static HostConfigEntryResolver toHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) { if (GenericUtils.isEmpty(entries)) { return HostConfigEntryResolver.EMPTY; } else { return (host1, port1, lclAddress, username1, ctx) -> { List<HostConfigEntry> matches = findMatchingEntries(host1, entries); int numMatches = GenericUtils.size(matches); if (numMatches <= 0) { return null; } HostConfigEntry match = (numMatches == 1) ? matches.get(0) : findBestMatch(matches); if (match == null) { ValidateUtils.throwIllegalArgumentException("No best match found for %s@%s:%d out of %d matches", username1, host1, port1, numMatches); } return normalizeEntry(match, host1, port1, username1); }; } }
/** * @param entries The entries - ignored if {@code null}/empty * @return A {@link HostConfigEntryResolver} wrapper using the entries */ public static HostConfigEntryResolver toHostConfigEntryResolver(Collection<? extends HostConfigEntry> entries) { if (GenericUtils.isEmpty(entries)) { return HostConfigEntryResolver.EMPTY; } else { return (host1, port1, username1) -> { List<HostConfigEntry> matches = findMatchingEntries(host1, entries); int numMatches = GenericUtils.size(matches); if (numMatches <= 0) { return null; } HostConfigEntry match = (numMatches == 1) ? matches.get(0) : findBestMatch(matches); if (match == null) { ValidateUtils.throwIllegalArgumentException("No best match found for %s@%s:%d out of %d matches", username1, host1, port1, numMatches); } return normalizeEntry(match, host1, port1, username1); }; } }