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.diorite.config.impl.proxy.ConfigInvocationHandler.java

private void registerVoidMethod(Class<? extends Config> clazz, Method method, Consumer<Object[]> func) {
    this.registerMethod(clazz, method, (a) -> {
        func.accept(a);
        return null;
    });/*from  w  w  w .  j av a 2 s.c om*/
}

From source file:org.apache.solr.cloud.AliasIntegrationTest.java

private void searchSeveralWays(String collectionList, SolrParams solrQuery,
        Consumer<QueryResponse> responseConsumer) throws IOException, SolrServerException {
    if (random().nextBoolean()) {
        // cluster's CloudSolrClient
        responseConsumer.accept(cluster.getSolrClient().query(collectionList, solrQuery));
    } else {/*from ww  w . jav  a  2s.c om*/
        // new CloudSolrClient (random shardLeadersOnly)
        try (CloudSolrClient solrClient = getCloudSolrClient(cluster)) {
            if (random().nextBoolean()) {
                solrClient.setDefaultCollection(collectionList);
                responseConsumer.accept(solrClient.query(null, solrQuery));
            } else {
                responseConsumer.accept(solrClient.query(collectionList, solrQuery));
            }
        }
    }

    // note: collectionList could be null when we randomly recurse and put the actual collection list into the
    //  "collection" param and some bugs value into collectionList (including null).  Only CloudSolrClient supports null.
    if (collectionList != null) {
        // HttpSolrClient
        JettySolrRunner jetty = cluster.getRandomJetty(random());
        if (random().nextBoolean()) {
            try (HttpSolrClient client = getHttpSolrClient(
                    jetty.getBaseUrl().toString() + "/" + collectionList)) {
                responseConsumer.accept(client.query(null, solrQuery));
            }
        } else {
            try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
                responseConsumer.accept(client.query(collectionList, solrQuery));
            }
        }

        // Recursively do again; this time with the &collection= param
        if (solrQuery.get("collection") == null) {
            // put in "collection" param
            ModifiableSolrParams newParams = new ModifiableSolrParams(solrQuery);
            newParams.set("collection", collectionList);
            String maskedColl = new String[] { null, "bogus", "collection2", "collection1" }[random()
                    .nextInt(4)];
            searchSeveralWays(maskedColl, newParams, responseConsumer);
        }
    }
}

From source file:org.azrul.langmera.QLearningAnalytics.java

public void getRandomDecision(DecisionRequest req, Vertx vertx, Consumer<DecisionResponse> responseAction) {
    getDecisionPreCondition(req);//from  w w w. ja va  2s. c  om
    Integer r = random.nextInt(req.getOptions().length);
    DecisionResponse resp = new DecisionResponse();
    resp.setDecision(req.getOptions()[r]);
    resp.setDecisionId(req.getDecisionId());
    //save cache to be matched to feedback
    if (req != null) {
        vertx.sharedData().getLocalMap("DECISION_REQUEST").put(req.getDecisionId(), req);
    }
    if (resp != null) {
        vertx.sharedData().getLocalMap("DECISION_RESPONSE").put(req.getDecisionId(), resp);
    }
    responseAction.accept(resp);
}

From source file:org.codelibs.fess.app.web.admin.backup.AdminBackupAction.java

private StreamResponse writeNdjsonResponse(final String id, final Consumer<Writer> writeCall) {
    return asStream(id)//
            .header("Pragma", "no-cache")//
            .header("Cache-Control", "no-cache")//
            .header("Expires", "Thu, 01 Dec 1994 16:00:00 GMT")//
            .header("Content-Type", "application/x-ndjson")//
            .stream(out -> {/*  www  .ja  va2 s. com*/
                try (final Writer writer = new BufferedWriter(
                        new OutputStreamWriter(out.stream(), Constants.CHARSET_UTF_8))) {
                    writeCall.accept(writer);
                    writer.flush();
                } catch (final Exception e) {
                    logger.warn("Failed to write " + id + " to response.", e);
                }
            });
}

From source file:org.commonjava.util.partyline.FileTree.java

/**
 * Iterate all {@link FileEntry instances} to extract information about active locks.
 *
 * @param predicate The selector determining which files to analyze.
 * @param fileConsumer The operation to extract information from a single active file.
 *//*from w  w w.ja v a2s .  c  o m*/
void forAll(Predicate<? super FileEntry> predicate, Consumer<FileEntry> fileConsumer) {
    TreeMap<String, FileEntry> sorted = new TreeMap<>(entryMap);
    sorted.forEach((key, entry) -> {
        if (entry != null && predicate.test(entry)) {
            fileConsumer.accept(entry);
        }
    });
}

From source file:org.codice.ddf.configuration.migration.ImportMigrationContextImpl.java

private void doImportGivenVersionLogic(Consumer<String> importVersionLogic) {
    if (migratable != null) {
        final String version = getMigratableVersion().orElse(null);

        if (skip) {
            LOGGER.debug("Skipping optional migratable [{}] with version [{}]", id, version);
            return;
        }/* w  w w.  j av a  2s  .com*/
        LOGGER.debug("Importing migratable [{}] from version [{}]...", id, version);
        Stopwatch stopwatch = null;

        if (LOGGER.isDebugEnabled()) {
            stopwatch = Stopwatch.createStarted();
        }
        try {
            importVersionLogic.accept(version);
        } finally {
            inputStreams.forEach(IOUtils::closeQuietly); // we do not care if we failed to close them
        }
        if (LOGGER.isDebugEnabled() && (stopwatch != null)) {
            LOGGER.debug("Imported time for {}: {}", id, stopwatch.stop());
        }
    } else if (id != null) { // not a system context
        LOGGER.warn("unable to import migration data for migratable [{}]; migratable is no longer available",
                id);
        report.record(new MigrationException(Messages.IMPORT_UNKNOWN_DATA_FOUND_ERROR));
    } // else - no errors and nothing to do for the system context
}

From source file:com.spotify.heroic.metadata.elasticsearch.MetadataBackendKV.java

private <T, O> AsyncFuture<O> entries(final Filter filter, final OptionalLimit limit, final DateRange range,
        final Function<SearchHit, T> converter, final Transform<LimitedSet<T>, O> collector,
        final Consumer<SearchRequestBuilder> modifier) {
    final QueryBuilder f = filter(filter);

    return doto(c -> {
        final SearchRequestBuilder builder = c.search(TYPE_METADATA).setScroll(SCROLL_TIME);

        builder.setSize(limit.asMaxInteger(SCROLL_SIZE));
        builder.setQuery(new BoolQueryBuilder().must(f));

        modifier.accept(builder);

        AsyncFuture<LimitedSet<T>> scroll = scrollEntries(c, builder, limit, converter);
        return scroll.directTransform(collector);
    });//from w w  w  .  j a va 2  s  .  c o  m
}

From source file:com.github.jsonj.JsonArray.java

public void forEachObject(Consumer<? super JsonObject> action) {
    for (JsonElement e : this) {
        action.accept(e.asObject());
    }//from w w w. ja  v  a2s.  c  o m
}

From source file:org.exist.launcher.Launcher.java

private void isRoot(Consumer<Boolean> consumer) {
    final List<String> args = new ArrayList<>(2);
    args.add("id");
    args.add("-u");
    run(args, (code, output) -> {//from ww  w.jav a  2s  . co m
        consumer.accept("0".equals(output.trim()));
    });
}

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

protected void createTextFieldInput(final ConfigFrame cf, final String propertyName, final String initialValue,
        final Consumer<String> applyValue, final Monospace monospace) {
    final TextField inputField = new TextField(initialValue);
    this.setMonospaceIfDesired(monospace, inputField);
    inputField.textProperty().addListener((ChangeListener<String>) (observable, oldValue, newValue) -> {
        applyValue.accept(newValue);
        this.getGraph().handleChange();
    });/*from   ww w. j av  a  2  s  . c  o  m*/
    cf.addOption(propertyName, inputField);
}