Example usage for java.util.function BiConsumer accept

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

Introduction

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

Prototype

void accept(T t, U u);

Source Link

Document

Performs this operation on the given arguments.

Usage

From source file:Main.java

public static void main(String[] args) {
    BiConsumer<String, String> biConsumer = (x, y) -> {
        System.out.println(x);//from  w w w  .j a v  a  2 s.c  om
        System.out.println(y);
    };

    biConsumer.accept("java2s.com", " tutorials");
}

From source file:Main.java

/**
 * Facility for executing lambdas requiring access to the index. The passed
 * function will run once per element of the list. Avoid side effects on the
 * list, they won't work correctly./*  ww w . j av  a 2 s  .co  m*/
 * 
 * @param <E>
 *            {@link List} data type
 * @param s
 *            the {@link List} to apply the lambda on
 * @param f
 *            the {@link BiConsumer} to apply to each element
 */
public static <E> void forEach(final List<E> s, final BiConsumer<? super Integer, ? super E> f) {
    for (int i = 0; i < s.size(); i++) {
        f.accept(i, s.get(i));
    }
}

From source file:Main.java

/**
 * Create a {@link T Sequence} of {@link E}.
 *
 * @param factory  Factory method to create sequence.
 * @param adder    Sequence adding method.
 * @param elements Array Elements to add to sequence.
 * @param <E>      Element type.//w w  w. ja  v a 2s.  co  m
 * @param <T>      Sequence type (non-java)
 * @return Created {@link T Sequence} with {@code elements}.
 */
@SafeVarargs
public static <E, T> T sequenceOf(Supplier<T> factory, BiConsumer<T, E> adder, E... elements) {
    T sequence = factory.get();

    for (E element : elements) {
        adder.accept(sequence, element);
    }

    return sequence;
}

From source file:Main.java

public static <K, V> void forEach(Map<K, V> m, BiConsumer<K, V> consumer) {
    if (isNullOrEmpty(m)) {
        return;/*www  . j a v a 2s .  c  om*/
    }
    for (Map.Entry<K, V> entry : m.entrySet()) {
        consumer.accept(entry.getKey(), entry.getValue());
    }
}

From source file:com.hcspider.platypusjs.asynchttp.AsyncHTTPCallbacks.java

public static FutureCallback<HttpResponse> asCallback(BiConsumer<Object, Throwable> aWrapped) {
    return new FutureCallback<HttpResponse>() {
        @Override// w  w w .ja va  2  s .  co  m
        public void completed(final HttpResponse response) {
            aWrapped.accept(response, null);
        }

        @Override
        public void failed(final Exception ex) {
            aWrapped.accept(null, ex);
        }

        @Override
        public void cancelled() {
            aWrapped.accept(null, new Exception("Async HTTP requst was cancelled."));
        }
    };
}

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

/** Collect network profile constraints for all networks associated with compute */
public static void getComputeNetworkProfileConstraints(ServiceHost host, URI referer, String contextId,
        ComputeDescription computeDesc, BiConsumer<Set<String>, Throwable> consumer) {
    if (computeDesc.networkInterfaceDescLinks == null || computeDesc.networkInterfaceDescLinks.isEmpty()) {
        consumer.accept(null, null);
        return;/*ww  w  .  j  av  a 2  s  .  co  m*/
    }
    getContextComputeNetworks(host, referer, contextId, consumer,
            (retrievedNetworks) -> getNetworkConstraints(host, referer, computeDesc, retrievedNetworks,
                    consumer));
}

From source file:at.gridtec.lambda4j.consumer.bi.BiConsumer2.java

/**
 * Calls the given {@link BiConsumer} with the given arguments and returns its result.
 *
 * @param <T> The type of the first argument to the consumer
 * @param <U> The type of the second argument to the consumer
 * @param consumer The consumer to be called
 * @param t The first argument to the consumer
 * @param u The second argument to the consumer
 * @throws NullPointerException If given argument is {@code null}
 *///from w w  w  .  j  a va  2  s  .c  o  m
static <T, U> void call(@Nonnull final BiConsumer<? super T, ? super U> consumer, T t, U u) {
    Objects.requireNonNull(consumer);
    consumer.accept(t, u);
}

From source file:com.ginema.api.enricher.SensitiveDataExtractor.java

public static <V> void populate(SensitiveDataHolder h, Map<String, V> map,
        BiConsumer<SensitiveDataHolder, Map<String, V>> biconsumer, String s, V value) {
    if (map == null)
        map = new HashMap<String, V>();

    map.put(s, value);// w  w  w  .jav a  2s. co  m
    biconsumer.accept(h, map);

}

From source file:gov.vha.isaac.ochre.api.LookupService.java

/**
 * start all core isaac services in a background thread, returning immediately.  
 * @param callWhenStartComplete (optional) - if provided,  a call back will be provided
 * notifying of successfully start of ISAAC, or providing the Exception, if the startup sequence failed.
 *//*from  w ww. j  a  v a  2 s .  com*/
public static void startupIsaac(BiConsumer<Boolean, Exception> callWhenStartComplete) {
    log.info("Background starting ISAAC services");
    Thread backgroundLoad = new Thread(() -> {
        try {
            startupIsaac();
            log.info("Background start complete - runlevel now "
                    + getService(RunLevelController.class).getCurrentRunLevel());
            if (callWhenStartComplete != null) {
                callWhenStartComplete.accept(isIsaacStarted(), null);
            }
        } catch (Exception e) {
            log.warn("Background start failed - runlevel now "
                    + getService(RunLevelController.class).getCurrentRunLevel(), e);
            if (callWhenStartComplete != null) {
                callWhenStartComplete.accept(false, e);
            }
        }
    }, "Datastore init thread");
    backgroundLoad.start();
}

From source file:ch.algotrader.starter.SimulationStarter.java

private static void runSimulation(final BiConsumer<SimulationExecutor, StrategyGroup> consumer) {
    final ServiceLocator serviceLocator = ServiceLocator.instance();
    serviceLocator.init(ServiceLocator.SIMULATION_BEAN_REFERENCE_LOCATION);
    try {/*from   www  . j a v a 2  s.com*/
        StrategyGroup strategyGroup;
        if (serviceLocator.getContext().containsBean("strategyGroup")) {
            strategyGroup = serviceLocator.getContext().getBean("strategyGroup", StrategyGroup.class);
        } else {
            final ConfigParams configParams = ConfigLocator.instance().getConfigParams();
            strategyGroup = StrategyGroup.single(configParams.getString("strategyName"));
        }
        SimulationExecutor executor = serviceLocator.getService("simulationExecutor", SimulationExecutor.class);
        consumer.accept(executor, strategyGroup);

    } finally {
        serviceLocator.shutdown();
    }
    // run a garbage collection
    System.gc();
}