All Downloads are FREE. Search and download functionalities are using the official Maven repository.

global.maplink.geocode.extensions.GeocodeExtension Maven / Gradle / Ivy

There is a newer version: 1.5.14
Show newest version
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;
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy