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:com.vmware.admiral.request.compute.NetworkProfileQueryUtils.java

private static void getContextComputeNetworks(ServiceHost host, URI referer, String contextId,
        BiConsumer<Set<String>, Throwable> consumer,
        Consumer<HashMap<String, ComputeNetwork>> callbackFunction) {
    HashMap<String, ComputeNetwork> contextNetworks = new HashMap<>();
    if (StringUtil.isNullOrEmpty(contextId)) {
        callbackFunction.accept(contextNetworks);
        return;/*from  w  ww .  ja va  2s.co  m*/
    }

    // Get all ComputeNetworks that have the same context id
    List<ComputeNetwork> computeNetworks = new ArrayList<>();
    QueryTask.Query.Builder builder = QueryTask.Query.Builder.create().addKindFieldClause(ComputeNetwork.class);
    builder.addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, FIELD_NAME_CONTEXT_ID_KEY,
            contextId);
    QueryUtils.QueryByPages<ComputeNetwork> query = new QueryUtils.QueryByPages<>(host, builder.build(),
            ComputeNetwork.class, null);
    query.queryDocuments(ns -> computeNetworks.add(ns)).whenComplete((v, e) -> {
        if (e != null) {
            consumer.accept(null, e);
            return;
        }
        // Get ComputeNetworkDescription of every network
        List<DeferredResult<Pair<String, ComputeNetwork>>> list = computeNetworks.stream()
                .map(cn -> host.sendWithDeferredResult(
                        Operation.createGet(host, cn.descriptionLink).setReferer(referer),
                        ComputeNetworkDescription.class).thenCompose(cnd -> {
                            DeferredResult<Pair<String, ComputeNetwork>> r = new DeferredResult<>();
                            r.complete(Pair.of(cnd.name, cn));
                            return r;
                        }))
                .collect(Collectors.toList());
        // Create a map of ComputeNetworkDescription.name to ComputeNetworkState
        DeferredResult.allOf(list).whenComplete((all, t) -> {
            all.forEach(p -> contextNetworks.put(p.getKey(), p.getValue()));
            callbackFunction.accept(contextNetworks);
        });
    });
}

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

private static void getNetworkConstraints(ServiceHost host, URI referer, ComputeDescription computeDescription,
        HashMap<String, ComputeNetwork> contextComputeNetworks, BiConsumer<Set<String>, Throwable> consumer) {
    DeferredResult<List<ComputeNetwork>> result = DeferredResult
            .allOf(computeDescription.networkInterfaceDescLinks.stream().map(nicDescLink -> {
                Operation op = Operation.createGet(host, nicDescLink).setReferer(referer);

                return host.sendWithDeferredResult(op, NetworkInterfaceDescription.class);
            }).map(nid -> nid.thenCompose(nic -> {
                ComputeNetwork computeNetwork = contextComputeNetworks.get(nic.name);
                if (computeNetwork == null) {
                    throw new LocalizableValidationException(
                            String.format("Could not find context network component with name '%s'.", nic.name),
                            "compute.network.component.not.found", nic.name);

                }/* w  w w.j  a v a 2s .  c  o m*/
                return DeferredResult.completed(computeNetwork);
            })).collect(Collectors.toList()));

    result.whenComplete((all, e) -> {
        if (e != null) {
            consumer.accept(null, e);
            return;
        }

        // Remove networks that don't have any constraints
        all.removeIf(cn -> cn.networkProfileLinks == null || cn.networkProfileLinks.isEmpty());
        if (all.isEmpty()) {
            consumer.accept(null, null);
            return;
        }
        Set<String> networkProfileLinks = all.get(0).networkProfileLinks;
        all.forEach(cn -> networkProfileLinks.retainAll(cn.networkProfileLinks));
        consumer.accept(networkProfileLinks, null);
    });
}

From source file:fi.ilmoeuro.membertrack.membership.MembershipsPageModel.java

@Override
public void saveState(BiConsumer<String, @Nullable String> pairConsumer) {
    pairConsumer.accept("page", String.valueOf(getCurrentPage()));
    Membership selected = membershipEditor.getMembership();
    if (selected != null) {
        pairConsumer.accept("selected", selected.getPerson().getEmail());
    } else {/*from www . j a  v  a  2  s  .  co m*/
        pairConsumer.accept("selected", null);
    }
    if (currentEditor != Editor.NONE) {
        pairConsumer.accept("editor", currentEditor.name().toLowerCase(Locale.ROOT));
    } else {
        pairConsumer.accept("editor", null);
    }
    String searchString = membershipBrowser.getSearchString();
    if (StringUtils.isBlank(searchString)) {
        pairConsumer.accept("search", null);
    } else {
        pairConsumer.accept("search", searchString);
    }
}

From source file:leap.lang.http.client.apache.ApacheHttpResponse.java

@Override
public void forEachHeaders(BiConsumer<String, String> func) {
    Header[] headers = response.getAllHeaders();
    if (null != headers) {
        for (Header header : headers) {
            func.accept(header.getName(), header.getValue());
        }/*from   ww w .java2  s.  c om*/
    }
}

From source file:com.cybernostics.jsp2thymeleaf.api.elements.CopyElementConverter.java

protected void doWithAttributes(JspElementContext jspNode, BiConsumer<Integer, HtmlAttributeContext> toDo) {
    final List<HtmlAttributeContext> atts = jspNode.atts;
    for (int i = 0; i < atts.size(); i++) {
        toDo.accept(i, atts.get(i));
    }//from   ww w  . java2s .c  o  m
}

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

/**
 * Returns a composed {@link BiConsumer2} that performs, in sequence, this consumer followed by the {@code after}
 * consumer./*  ww  w.j  a  v  a2  s  .co  m*/
 * If evaluation of either operation throws an exception, it is relayed to the caller of the composed operation.
 * If performing this consumer throws an exception, the {@code after} consumer will not be performed.
 *
 * @param after The consumer to apply after this consumer is applied
 * @return A composed {@link BiConsumer2} that performs, in sequence, this consumer followed by the {@code after}
 * consumer.
 * @throws NullPointerException If given argument is {@code null}
 */
@Nonnull
default BiConsumer2<T, U> andThen(@Nonnull final BiConsumer<? super T, ? super U> after) {
    Objects.requireNonNull(after);
    return (t, u) -> {
        accept(t, u);
        after.accept(t, u);
    };
}

From source file:natalia.dymnikova.cluster.scheduler.impl.BasicChildrenCreatorTest.java

@Test
public void shouldSendCompleteToNextStage() throws Exception {
    givenCreator(flow);//from  ww w .j av a 2  s  .  c o m

    childrenCreator.apply(flowControlActor);

    final ArgumentCaptor<BiConsumer> captor = ArgumentCaptor.forClass(BiConsumer.class);
    verify(context, atLeastOnce()).getBean(same(OutSubscriberFactory.class), captor.capture());

    final BiConsumer allValues = captor.getValue();
    final ActorSelection next = mock(ActorSelection.class);
    final ActorRef parent = spy(new TestActorRef());
    allValues.accept(Pair.create(Optional.of(next), parent), self);

    verify(next).tell(eq(Flow.Completed.getDefaultInstance()), same(self));
}

From source file:natalia.dymnikova.cluster.scheduler.impl.BasicChildrenCreatorTest.java

@Test
public void shouldSendCompleteToParentStage() throws Exception {
    givenCreator(flow);/*from  w  w w. j  a  v a2 s . co  m*/

    doReturn(parse(Host2)).when(cluster).selfAddress();
    childrenCreator.apply(flowControlActor);

    final ArgumentCaptor<BiConsumer> captor = ArgumentCaptor.forClass(BiConsumer.class);
    verify(context, atLeastOnce()).getBean(same(OutSubscriberFactory.class), captor.capture());

    final BiConsumer allValues = captor.getValue();
    final ActorSelection next = mock(ActorSelection.class);
    final ActorRef parent = spy(new TestActorRef());
    allValues.accept(Pair.create(next, parent), self);

    verify(parent).tell(eq(Flow.Completed.getDefaultInstance()), same(self));
}

From source file:enumj.StreamComparator.java

public void test(BiConsumer<T, Optional<T>> elemAssert, Runnable lengthMismatchAsserter) {
    if (!built) {
        build();//from w ww  .  j  a  v  a  2  s  . c o  m
    }

    lhs.forEach(x -> elemAssert.accept(x, Optional.ofNullable(rhsHasNext() ? rhsNext() : null)));
    if (rhsHasNext()) {
        lengthMismatchAsserter.run();
    }
}

From source file:Main.java

private static <E> void updateList(List<E> origList, Collection<? extends E> updateList, boolean add,
        boolean replace, boolean remove, BiPredicate<? super E, ? super E> equalTester,
        BiConsumer<List<E>, Collection<? extends E>> adder) {
    List<E> itemsToRemove = null;
    List<E> itemsToAdd = null;
    for (E update : updateList) {
        boolean origListContainsUpdate = false;
        ListIterator<E> origIter = origList.listIterator();
        while (origIter.hasNext()) {
            E orig = origIter.next();/*from w w w.  j ava 2 s . co m*/
            if (equalTester.test(orig, update)) {
                origListContainsUpdate = true;
                if (remove) {
                    if (itemsToRemove == null) {
                        itemsToRemove = new ArrayList<>(origList);
                    }
                    itemsToRemove.remove(orig);
                }
                if (replace) {
                    origIter.set(update);
                }
                break;
            }
        }
        if (!origListContainsUpdate && add) {
            if (itemsToAdd == null) {
                itemsToAdd = new ArrayList<>();
            }
            itemsToAdd.add(update);
        }
    }
    if (remove) {
        if (itemsToRemove != null) {
            origList.removeAll(itemsToRemove);
        } else {
            origList.clear();
        }
    }
    if (itemsToAdd != null) {
        adder.accept(origList, itemsToAdd);
    }
}