private final List<PolicyFilter> filters;
private final MatchersByTypeIndex matchersIndex;
@Override
public boolean filter(HttpServletRequest request, Route route,
RateLimitProperties.Policy policy) {
return policy.getType().isEmpty() || allFiltersApply(request, route, policy);
}
private boolean allFiltersApply(HttpServletRequest request, Route route,
RateLimitProperties.Policy policy) {
return filters
.stream()
.allMatch(policyFilter -> {
Set<String> matchers = matchersIndex.get(policyFilter.getType());
return policyFilter.filter(matchers, request, route);
});
}
private boolean urlApply(List<MatchType> types, Route route) {
List<String> urls = getConfiguredType(types, Type.URL);
return urls.isEmpty()
|| route == null
|| urls.stream().anyMatch(url -> route.getPath().startsWith(url));
}
private boolean urlApply(List<MatchType> types, Route route) {
Set<String> urls = matchersIndex.getOrDefault(Type.URL, Collections.emptySet());
return urls.isEmpty()
|| route == null
|| urls.stream().anyMatch(url -> route.getPath().startsWith(url));
}
This would decrease complexity of the method.
If you are interested I would like to open PRs with described changes.