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:org.geoserver.opensearch.rest.ProductsController.java

private Feature queryProduct(String collection, String product, Consumer<Query> queryDecorator)
        throws IOException {
    // query products
    Query query = new Query();
    Filter filter = getProductFilter(collection, product);
    query.setFilter(filter);/*from w w  w.  j ava  2s  .co m*/
    queryDecorator.accept(query);
    OpenSearchAccess access = accessProvider.getOpenSearchAccess();
    FeatureSource<FeatureType, Feature> fs = access.getProductSource();
    FeatureCollection<FeatureType, Feature> features = fs.getFeatures(query);
    Feature feature = DataUtilities.first(features);

    if (feature == null) {
        throwProductNotFound(collection, product, "Product");
    }

    return feature;
}

From source file:de.pixida.logtest.designer.automaton.AutomatonEdge.java

private Node createRadioButtonInput(final ToggleGroup tg, final String propertyName,
        final boolean isInitiallySelected, final Consumer<Boolean> applyValue) {
    final RadioButton result = new RadioButton(propertyName);
    result.setToggleGroup(tg);/*  w w w  .j  a  v  a 2 s .  c om*/
    result.setSelected(isInitiallySelected);
    result.setOnAction(event -> {
        applyValue.accept(result.isSelected());
        this.getGraph().handleChange();
    });
    return result;
}

From source file:io.mapzone.arena.refine.FeatureSourceSelectorUI.java

public FeatureSourceSelectorUI(final MdToolkit tk, final Composite parent,
        final Consumer<FeatureSource> onSelect) throws IOException {
    this.combo = new Combo(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN);

    final List<Name> featureSourceNames = P4Plugin.localCatalog().localFeaturesStore().getNames();
    // final List<String> featureSources = featureSourceNames.stream().map(
    // name -> name.getLocalPart() ).collect( Collectors.toList() );
    combo.setItems(featureSourceNames.stream().map(name -> name.getLocalPart()).toArray(String[]::new));
    combo.addSelectionListener(new SelectionAdapter() {

        @Override/*from   w w  w  .  j a va2 s .  co  m*/
        public void widgetSelected(SelectionEvent e) {
            try {
                Name featureSourceName = featureSourceNames.get(combo.getSelectionIndex());
                onSelect.accept(
                        P4Plugin.localCatalog().localFeaturesStore().getFeatureSource(featureSourceName));
            } catch (IOException e1) {
                StatusDispatcher.handleError("", e1);
            }
        }

    });
}

From source file:org.commonjava.indy.pkg.npm.jaxrs.NPMContentAccessHandler.java

@Override
public Response doHead(final String packageType, final String type, final String name, final String path,
        final Boolean cacheOnly, final String baseUri, final HttpServletRequest request,
        EventMetadata eventMetadata, final Consumer<Response.ResponseBuilder> builderModifier) {
    if (!PackageTypes.contains(packageType)) {
        Response.ResponseBuilder builder = Response.status(400);
        if (builderModifier != null) {
            builderModifier.accept(builder);
        }//from  w  w w . j a  va2  s . c  o m
        return builder.build();
    }

    final StoreType st = StoreType.get(type);
    final StoreKey sk = new StoreKey(packageType, st, name);

    eventMetadata = eventMetadata.set(ContentManager.ENTRY_POINT_STORE, sk);

    final AcceptInfo acceptInfo = jaxRsRequestHelper.findAccept(request, ApplicationContent.text_html);

    Response response = null;

    if (path == null || path.equals("")) {
        try {
            logger.info("Getting listing at: {}", path);
            final String content = contentController.renderListing(acceptInfo.getBaseAccept(), sk, path,
                    baseUri, uriFormatter);

            Response.ResponseBuilder builder = Response.ok()
                    .header(ApplicationHeader.content_type.key(), acceptInfo.getRawAccept())
                    .header(ApplicationHeader.content_length.key(), Long.toString(content.length()))
                    .header(ApplicationHeader.last_modified.key(), HttpUtils.formatDateHeader(new Date()));
            if (builderModifier != null) {
                builderModifier.accept(builder);
            }
            response = builder.build();
        } catch (final IndyWorkflowException e) {
            logger.error(String.format("Failed to list content: %s from: %s. Reason: %s", path, name,
                    e.getMessage()), e);
            response = formatResponse(e, builderModifier);
        }
    } else {
        try {
            Transfer item = null;
            logger.info("Checking existence of: {}:{} (cache only? {})", sk, path, cacheOnly);

            boolean exists = false;
            if (Boolean.TRUE.equals(cacheOnly)) {
                logger.debug("Calling getTransfer()");
                item = contentController.getTransfer(sk, path, TransferOperation.DOWNLOAD);
                exists = item != null && item.exists();
                logger.debug("Got transfer reference: {}", item);
            } else {
                logger.debug("Calling remote exists()");
                exists = contentController.exists(sk, path);
                logger.debug("Got remote exists: {}", exists);
            }

            if (exists) {
                // for npm will fetch the http-meta as the mapping path directly to get the headers info for further header set
                HttpExchangeMetadata httpMetadata = contentController.getHttpMetadata(sk,
                        PathUtils.storagePath(path, eventMetadata));

                if (item == null) {
                    logger.info("Retrieving: {}:{} for existence test", sk, path);
                    item = contentController.get(sk, path, eventMetadata);
                    logger.debug("Got retrieved transfer reference: {}", item);
                }

                logger.debug("Building 200 response. Using HTTP metadata: {}", httpMetadata);

                final Response.ResponseBuilder builder = Response.ok();

                setInfoHeaders(builder, item, sk, path, true, getNPMContentType(path), httpMetadata);
                if (builderModifier != null) {
                    builderModifier.accept(builder);
                }
                response = builder.build();
            } else {
                logger.debug("Building 404 (or error) response...");
                if (StoreType.remote == st) {
                    final HttpExchangeMetadata metadata = contentController.getHttpMetadata(sk, path);
                    if (metadata != null) {
                        logger.debug("Using HTTP metadata to build negative response.");
                        response = formatResponseFromMetadata(metadata);
                    }
                }

                if (response == null) {
                    logger.debug("No HTTP metadata; building generic 404 response.");
                    Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
                    if (builderModifier != null) {
                        builderModifier.accept(builder);
                    }
                    response = builder.build();
                }
            }
        } catch (final IndyWorkflowException e) {
            logger.error(String.format("Failed to download artifact: %s from: %s. Reason: %s", path, name,
                    e.getMessage()), e);
            response = formatResponse(e, builderModifier);
        }
    }
    return response;
}

From source file:org.eclipse.sw360.portal.portlets.admin.ComponentUploadPortlet.java

private void printAttachments(Set<Attachment> attachments, List<Iterable<String>> csvRows,
        Consumer<ComponentAttachmentCSVRecordBuilder> containingObjectPrinter) {
    if (attachments != null && !attachments.isEmpty()) {
        for (Attachment attachment : attachments) {
            final ComponentAttachmentCSVRecordBuilder componentAttachmentCSVRecordBuilder = ComponentAttachmentCSVRecord
                    .builder();/*from   w  w  w. jav  a  2  s  . co m*/
            containingObjectPrinter.accept(componentAttachmentCSVRecordBuilder);
            componentAttachmentCSVRecordBuilder.fill(attachment);
            csvRows.add(componentAttachmentCSVRecordBuilder.build().getCSVIterable());
        }
    }
}

From source file:de.metas.ui.web.vaadin.window.WindowPresenter.java

private final void updateView(final Consumer<WindowView> consumer) {
    final WindowView view = getView();
    if (view == null) {
        return;/*from ww  w. ja  va 2  s.  c  o m*/
    }

    final UI viewUI = getUI();
    final UI currentUI = UI.getCurrent();
    if (viewUI != null && viewUI != currentUI) {
        logger.trace("Updating view on UI: {}", viewUI);
        viewUI.access(() -> consumer.accept(view));
    } else {
        logger.trace("Updating view directly (viewUI={}, currentUI={})", viewUI, currentUI);
        consumer.accept(view);
    }
}

From source file:io.mapzone.arena.analytics.graph.ui.FeatureSourceSelectorUI.java

public FeatureSourceSelectorUI(final MdToolkit tk, final Composite parent,
        final Consumer<FeatureSource> onSelect) throws IOException {
    this.combo = new Combo(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);

    final List<Name> featureSourceNames = P4Plugin.localCatalog().localFeaturesStore().getNames();
    // final List<String> featureSources = featureSourceNames.stream().map(
    // name -> name.getLocalPart() ).collect( Collectors.toList() );
    combo.setItems(featureSourceNames.stream().map(name -> name.getLocalPart()).toArray(String[]::new));
    combo.addSelectionListener(new SelectionAdapter() {

        @Override/*from  www . ja v  a2  s  .  com*/
        public void widgetSelected(SelectionEvent e) {
            try {
                Name featureSourceName = featureSourceNames.get(combo.getSelectionIndex());
                onSelect.accept(
                        P4Plugin.localCatalog().localFeaturesStore().getFeatureSource(featureSourceName));
            } catch (IOException e1) {
                StatusDispatcher.handleError("", e1);
            }
        }

    });
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

private void registerVoidMethod(Method method, Consumer<Object[]> func) {
    this.basicMethods.put(method, (a) -> {
        func.accept(a);
        return null;
    });//from   ww w. java  2  s  .c om
}

From source file:org.jsweet.test.transpiler.AbstractTest.java

protected void transpile(ModuleKind moduleKind, Consumer<TestTranspilationHandler> assertions,
        SourceFile... files) {// www. j  a  va  2  s.  co m
    ModuleKind initialModuleKind = transpiler.getModuleKind();
    File initialOutputDir = transpiler.getTsOutputDir();
    try {
        logger.info(
                "*** module kind: " + moduleKind + (transpiler.isBundle() ? " (with bundle)" : "") + " ***");
        TestTranspilationHandler logHandler = new TestTranspilationHandler();
        transpiler.setModuleKind(moduleKind);
        initOutputDir();
        transpiler.transpile(logHandler, files);
        if (assertions != null) {
            assertions.accept(logHandler);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("exception occured while running test " + getCurrentTestName() + " with module kind "
                + moduleKind);
    } finally {
        transpiler.setModuleKind(initialModuleKind);
        transpiler.setTsOutputDir(initialOutputDir);
    }
    if (moduleKind == ModuleKind.none && !transpiler.isBundle() && files.length > 1) {
        ArrayUtils.reverse(files);
        transpiler.setBundle(true);
        try {
            transpile(moduleKind, assertions, files);
        } finally {
            transpiler.setBundle(false);
            ArrayUtils.reverse(files);
        }
    }
}

From source file:org.keycloak.testsuite.adapter.servlet.cluster.AbstractSAMLAdapterClusterTest.java

protected void testLogoutViaSessionIndex(URL employeeUrl,
        Consumer<EmployeeServletDistributable> logoutFunction) {
    EmployeeServletDistributable page = PageFactory.initElements(driver, EmployeeServletDistributable.class);
    page.setUrl(employeeUrl);//w  w w  .  j  a va 2 s .c o  m
    page.getUriBuilder().port(HTTP_PORT_NODE_REVPROXY);

    UserRepresentation bburkeUser = createUserRepresentation("bburke", "bburke@redhat.com", "Bill", "Burke",
            true);
    setPasswordFor(bburkeUser, CredentialRepresentation.PASSWORD);

    assertSuccessfulLogin(page, bburkeUser, testRealmSAMLPostLoginPage, "principal=bburke");

    updateProxy(NODE_2_NAME, NODE_2_URI, NODE_1_URI);
    logoutFunction.accept(page);
    delayedCheckLoggedOut(page, loginActionsPage);

    updateProxy(NODE_1_NAME, NODE_1_URI, NODE_2_URI);
    delayedCheckLoggedOut(page, loginActionsPage);
}