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

org.zalando.riptide.RoutingTree Maven / Gradle / Ivy

package org.zalando.riptide;

import org.springframework.http.client.ClientHttpResponse;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static java.util.Arrays.asList;

/**
 * A routing tree is a nested {@link Route route} that consists of a {@link Navigator navigator} and a set of
 * {@link Binding bindings}. When being {@link Route#execute(ClientHttpResponse, MessageReader) executed} the navigator
 * will select the attribute value of the returned {@link ClientHttpResponse response}, find the correct binding
 * and execute {@link Binding#getRoute() it's route}. Since a routing tree is a route itself they can be nested
 * recursively inside each other to produce complex graphs.
 *
 * @param  generic attribute type
 * @see Route
 */
public interface RoutingTree extends Route {

    Navigator getNavigator();

    Set keySet();

    Optional get(final A attribute);

    Optional getWildcard();

    /**
     * @throws NoWildcardException if no route, not even a wildcard, exists for the given response
     */
    @Override
    void execute(final ClientHttpResponse response, final MessageReader reader) throws Exception;

    default RoutingTree merge(final Binding binding) {
        return merge(Collections.singletonList(binding));
    }

    RoutingTree merge(final List> bindings);

    @SafeVarargs
    static  RoutingTree dispatch(final Navigator navigator, final Binding... bindings) {
        return dispatch(navigator, asList(bindings));
    }

    static  RoutingTree dispatch(final Navigator navigator, final List> bindings) {
        return new DefaultRoutingTree<>(navigator, bindings);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy