Example usage for java.util.function Consumer accept

List of usage examples for java.util.function Consumer accept

Introduction

In this page you can find the example usage for java.util.function Consumer accept.

Prototype

void accept(T t);

Source Link

Document

Performs this operation on the given argument.

Usage

From source file:groovyx.net.http.ApacheHttpBuilder.java

/**
 * Creates a new `HttpBuilder` based on the Apache HTTP client. While it is acceptable to create a builder with this method, it is generally
 * preferred to use one of the `static` `configure(...)` methods.
 *
 * @param config the configuration object
 *//*from w w w. j av a 2  s.  c o  m*/
public ApacheHttpBuilder(final HttpObjectConfig config) {
    super(config);

    this.proxyInfo = config.getExecution().getProxyInfo();
    this.config = new HttpConfigs.ThreadSafeHttpConfig(config.getChainedConfig());
    this.executor = config.getExecution().getExecutor();
    this.clientConfig = config.getClient();

    final HttpClientBuilder myBuilder = HttpClients.custom();

    final Registry<ConnectionSocketFactory> registry = registry(config);

    if (config.getExecution().getMaxThreads() > 1) {
        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
        cm.setMaxTotal(config.getExecution().getMaxThreads());
        cm.setDefaultMaxPerRoute(config.getExecution().getMaxThreads());
        myBuilder.setConnectionManager(cm);
    } else {
        final BasicHttpClientConnectionManager cm = new BasicHttpClientConnectionManager(registry);
        myBuilder.setConnectionManager(cm);
    }

    final SSLContext sslContext = config.getExecution().getSslContext();
    if (sslContext != null) {
        myBuilder.setSSLContext(sslContext);
        myBuilder.setSSLSocketFactory(
                new SSLConnectionSocketFactory(sslContext, config.getExecution().getHostnameVerifier()));
    }

    myBuilder.addInterceptorFirst((HttpResponseInterceptor) (response, context) -> {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            Header ceheader = entity.getContentEncoding();
            if (ceheader != null) {
                HeaderElement[] codecs = ceheader.getElements();
                for (HeaderElement codec : codecs) {
                    if (codec.getName().equalsIgnoreCase("gzip")) {
                        response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                        return;
                    }
                }
            }
        }
    });

    final Consumer<Object> clientCustomizer = clientConfig.getClientCustomizer();
    if (clientCustomizer != null) {
        clientCustomizer.accept(myBuilder);
    }

    this.client = myBuilder.build();
}

From source file:com.example.app.ui.DemoUserProfileEditor.java

/**
 * Iterate over value editors.//from w w w .  j  av  a 2s. co m
 *
 * @param consumer the consumer.
 */
private void _forEach(Consumer<ValueEditor<?>> consumer) {
    ComponentTreeIterator cti = new ComponentTreeIterator(this, false, false, false);

    while (cti.hasNext()) {
        Component c = cti.next();
        if (c == this)
            continue;
        if (c instanceof ValueEditor<?>)
            consumer.accept(ValueEditor.class.cast(c));
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiByteFunction.java

/**
 * Returns a composed {@link ObjBiByteConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiByteConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//*from   w w w.  j  a v a  2 s  . c om*/
@Nonnull
default ObjBiByteConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiCharFunction.java

/**
 * Returns a composed {@link ObjBiCharConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiCharConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//* w  w  w .  j  a v a  2  s.c  om*/
@Nonnull
default ObjBiCharConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiFloatFunction.java

/**
 * Returns a composed {@link ObjBiFloatConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiFloatConsumer} that first applies this function to its input, and then consumes
 * the result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//*from w  w  w .  j av a 2  s.  c om*/
@Nonnull
default ObjBiFloatConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiShortFunction.java

/**
 * Returns a composed {@link ObjBiShortConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiShortConsumer} that first applies this function to its input, and then consumes
 * the result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *///from w  w  w.j  a  v a  2  s .c  o m
@Nonnull
default ObjBiShortConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiIntFunction.java

/**
 * Returns a composed {@link ObjBiIntConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiIntConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *///from  w w  w  .j ava  2  s . c  o m
@Nonnull
default ObjBiIntConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiLongFunction.java

/**
 * Returns a composed {@link ObjBiLongConsumer} that fist applies this function to its input, and then consumes the
 * result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed to
 * the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiLongConsumer} that first applies this function to its input, and then consumes the
 * result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//*from  w w  w  . j a  v  a2 s  .c om*/
@Nonnull
default ObjBiLongConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:at.gridtec.lambda4j.function.tri.obj.ObjBiDoubleFunction.java

/**
 * Returns a composed {@link ObjBiDoubleConsumer} that fist applies this function to its input, and then consumes
 * the result using the given {@link Consumer}. If evaluation of either operation throws an exception, it is relayed
 * to the caller of the composed operation.
 *
 * @param consumer The operation which consumes the result from this operation
 * @return A composed {@code ObjBiDoubleConsumer} that first applies this function to its input, and then consumes
 * the result using the given {@code Consumer}.
 * @throws NullPointerException If given argument is {@code null}
 *//*from w w w  . j a v a 2  s  . c o m*/
@Nonnull
default ObjBiDoubleConsumer<T> consume(@Nonnull final Consumer<? super R> consumer) {
    Objects.requireNonNull(consumer);
    return (t, value1, value2) -> consumer.accept(apply(t, value1, value2));
}

From source file:com.vmware.admiral.request.compute.ComputeReservationTaskService.java

private void getComputeDescription(String resourceDescriptionLink,
        Consumer<ComputeDescription> callbackFunction) {
    if (this.computeDescription != null) {
        callbackFunction.accept(this.computeDescription);
        return;/*from w  w  w.  ja  va 2 s  .c o m*/
    }
    sendRequest(Operation.createGet(this, resourceDescriptionLink).setCompletion((o, e) -> {
        if (e != null) {
            failTask("Failure retrieving description state", e);
            return;
        }

        this.computeDescription = o.getBody(ComputeDescription.class);
        callbackFunction.accept(this.computeDescription);
    }));
}