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

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

The newest version!
package org.zalando.riptide;

import com.google.common.reflect.TypeToken;
import org.apiguardian.api.API;
import org.springframework.http.client.ClientHttpResponse;
import org.zalando.fauxpas.ThrowingConsumer;
import org.zalando.fauxpas.ThrowingRunnable;

import javax.annotation.Nullable;

import static org.apiguardian.api.API.Status.STABLE;

/**
 * A partial {@link Binding binding} that already has an attribute associated but is missing a {@link Route route}.
 * The functionality provided by this class is just syntactic sugar. Clients could use
 * {@link Binding#create(Object, Route)} directly.
 *
 * @see Binding#create(Object, Route)
 * @param  generic attribute.
 */
@API(status = STABLE)
public final class PartialBinding {

    private final A attribute;

    PartialBinding(@Nullable final A attribute) {
        this.attribute = attribute;
    }

    public Binding call(final ThrowingRunnable consumer) {
        return call(Route.call(consumer));
    }

    public Binding call(final ThrowingConsumer consumer) {
        return call(Route.call(consumer));
    }

    public  Binding call(final Class type, final ThrowingConsumer consumer) {
        return call(Route.call(type, consumer));
    }

    public  Binding call(final TypeToken type, final ThrowingConsumer consumer) {
        return call(Route.call(type, consumer));
    }

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

    public Binding call(final Route route) {
        return Binding.create(attribute, route);
    }

}