global.maplink.geocode.extensions.GeocodeExtension Maven / Gradle / Ivy
package global.maplink.geocode.extensions;
import global.maplink.extensions.SdkExtension;
import global.maplink.geocode.schema.GeocodeServiceRequest;
import global.maplink.geocode.schema.suggestions.SuggestionsResult;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import static java.lang.String.format;
import static java.util.concurrent.CompletableFuture.completedFuture;
public interface GeocodeExtension extends SdkExtension {
Class getRequestType();
default CompletableFuture doRequest(REQ request, Function> action) {
return processRequest(request).thenCompose(action).thenCompose(this::processResponse);
}
default CompletableFuture processRequest(REQ response) {
return completedFuture(response);
}
default CompletableFuture processResponse(SuggestionsResult response) {
return completedFuture(response);
}
static GeocodeExtension empty(Class requestType) {
return new GeocodeExtension() {
private final String name = format("Empty extension for [%s]", requestType.getName());
@Override
public Class getRequestType() {
return requestType;
}
@Override
public String getName() {
return name;
}
};
}
}