Skip to content

Commit

Permalink
Chore: Resolve multiple TODOs
Browse files Browse the repository at this point in the history
- Use BiPredicate for return type check in doDiscover.
- Replace hardcoded scheme checks with Set in isSecure.
  • Loading branch information
qingbozhang committed Jan 8, 2025
1 parent cf916f3 commit 2850a22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Supplier;

import org.apache.commons.logging.Log;
Expand All @@ -38,6 +39,8 @@ public abstract class AbstractGatewayDiscoverer {

protected volatile MultiValueMap<String, OperationMethod> operations = new LinkedMultiValueMap<>();

private final BiPredicate<Method, Class<?>> returnTypePredicate = (method, returnType) -> returnType.isAssignableFrom(method.getReturnType());

public <T extends Supplier<Collection<Method>>, R> void doDiscover(Class<T> supplierClass, Class<R> returnType) {
List<T> suppliers = loadSuppliers(supplierClass);

Expand All @@ -59,8 +62,7 @@ else if (log.isTraceEnabled()) {
}

for (Method method : methods) {
// TODO: replace with a BiPredicate of some kind
if (returnType.isAssignableFrom(method.getReturnType())) {
if (returnTypePredicate.test(method, returnType)) {
addOperationMethod(method);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ static class DelegatingServiceInstance implements ServiceInstance {

private String overrideScheme;

private static final Set<String> SECURE_SCHEMES = Set.of("https", "wss");

DelegatingServiceInstance(ServiceInstance delegate, String overrideScheme) {
this.delegate = delegate;
this.overrideScheme = overrideScheme;
Expand All @@ -169,8 +171,7 @@ public int getPort() {

@Override
public boolean isSecure() {
// TODO: move to map
if ("https".equals(this.overrideScheme) || "wss".equals(this.overrideScheme)) {
if (SECURE_SCHEMES.contains(this.overrideScheme)) {
return true;
}
return delegate.isSecure();
Expand Down

0 comments on commit 2850a22

Please sign in to comment.