Example usage for java.util List forEach

List of usage examples for java.util List forEach

Introduction

In this page you can find the example usage for java.util List forEach.

Prototype

default void forEach(Consumer<? super T> action) 

Source Link

Document

Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception.

Usage

From source file:de.tynne.benchmarksuite.Main.java

/** Returns a producer for all benchmarks in the named suites.
 *//*from w w w  .j  a va2  s.  c  o  m*/
private static BenchmarkProducer findAllByName(List<String> suiteNames,
        Map<BenchmarkSuite, BenchmarkProducer> suites) {
    List<BenchmarkProducer> benchmarkProducers = suiteNames.stream().map(s -> findByName(s, suites))
            .filter(bp -> bp.isPresent()).map(o -> o.get()).collect(Collectors.toList());

    return () -> {
        List<Benchmark> result = new ArrayList<>();
        benchmarkProducers.forEach(bp -> {
            result.addAll(bp.get());
        });
        return result;
    };
}

From source file:org.neo4j.nlp.examples.wikipedia.main.java

private static void trainOnText(String[] text, String[] label) {
    List<String> labelSet = new ArrayList<>();
    List<String> textSet = new ArrayList<>();

    Collections.addAll(labelSet, label);
    Collections.addAll(textSet, text);

    JsonArray labelArray = new JsonArray();
    JsonArray textArray = new JsonArray();

    labelSet.forEach((s) -> labelArray.add(new JsonPrimitive(s)));
    textSet.forEach((s) -> textArray.add(new JsonPrimitive(s)));

    JsonObject jsonParam = new JsonObject();
    jsonParam.add("text", textArray);
    jsonParam.add("label", labelArray);
    jsonParam.add("focus", new JsonPrimitive(2));

    String jsonPayload = new Gson().toJson(jsonParam);

    executePost("http://localhost:7474/service/graphify/training", jsonPayload);
}

From source file:edu.usu.sdl.openstorefront.core.view.UserProfileView.java

public static List<UserProfileView> toViewList(List<UserProfile> profiles) {
    Map<String, Date> loginMap = ServiceProxyFactory.getServiceProxy().getUserService().getLastLogin(profiles);
    List<UserProfileView> views = new ArrayList<>();
    profiles.forEach(profile -> {
        views.add(UserProfileView.toView(profile, loginMap));
    });//from  ww w.jav  a2 s . com

    return views;
}

From source file:alluxio.cli.ValidateEnv.java

private static ValidationTask registerTask(String name, String description, ValidationTask task,
        List<ValidationTask> tasks) {
    TASKS.put(task, name);/*from w ww  .  ja  va2  s.com*/
    TASK_DESCRIPTIONS.put(name, description);
    tasks.add(task);
    List<Option> optList = task.getOptionList();
    synchronized (ValidateEnv.class) {
        optList.forEach(opt -> OPTIONS.addOption(opt));
    }
    return task;
}

From source file:org.neo4j.nlp.examples.author.main.java

private static void trainOnText(String[] text, String[] label) {
    List<String> labelSet = new ArrayList<>();
    List<String> textSet = new ArrayList<>();

    Collections.addAll(labelSet, label);
    Collections.addAll(textSet, text);

    JsonArray labelArray = new JsonArray();
    JsonArray textArray = new JsonArray();

    labelSet.forEach((s) -> labelArray.add(new JsonPrimitive(s)));
    textSet.forEach((s) -> textArray.add(new JsonPrimitive(s)));

    JsonObject jsonParam = new JsonObject();
    jsonParam.add("text", textArray);
    jsonParam.add("label", labelArray);
    jsonParam.add("focus", new JsonPrimitive(2));

    String jsonPayload = new Gson().toJson(jsonParam);

    System.out.println(executePost("http://localhost:7474/service/graphify/training", jsonPayload));
}

From source file:com.excelsiorjet.api.util.Utils.java

public static void linesToFile(List<String> lines, File file) throws FileNotFoundException {
    try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file)))) {
        lines.forEach(out::println);
    }//from  w  w w. j a v  a2  s.co  m
}

From source file:org.neo4j.nlp.examples.sentiment.main.java

private static void trainOnText(String[] text, String[] label) {
    List<String> labelSet = new ArrayList<>();
    List<String> textSet = new ArrayList<>();

    Collections.addAll(labelSet, label);
    Collections.addAll(textSet, text);

    JsonArray labelArray = new JsonArray();
    JsonArray textArray = new JsonArray();

    labelSet.forEach((s) -> labelArray.add(new JsonPrimitive(s)));
    textSet.forEach((s) -> textArray.add(new JsonPrimitive(s)));

    JsonObject jsonParam = new JsonObject();
    jsonParam.add("text", textArray);
    jsonParam.add("label", labelArray);
    jsonParam.add("focus", new JsonPrimitive(1));

    String jsonPayload = new Gson().toJson(jsonParam);

    System.out.println(executePost("http://localhost:7474/service/graphify/training", jsonPayload));
}

From source file:io.ignitr.dispatchr.manager.domain.subscription.FindSubscriptionsResponse.java

/**
 *
 * @param metadatas/*from w w  w.  j  a va 2  s .  co m*/
 * @return
 */
public static FindSubscriptionsResponse from(List<Subscription> metadatas) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss zzz");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

    FindSubscriptionsResponse response = new FindSubscriptionsResponse();

    metadatas.forEach(metadata -> {
        Result result = new Result();
        result.setSubscriptionId(metadata.getId());
        result.setClientId(metadata.getClientId());
        result.setTopic(metadata.getTopicName());
        result.setTopicArn(metadata.getTopicArn());
        result.setQueueArn(metadata.getQueueArn());
        result.setCreateDate(sdf.format(new Date(metadata.getCreateDate())));
        result.setLastSubscribeDate(sdf.format(new Date(metadata.getLastSubscribeDate())));

        result.add(linkTo(methodOn(TopicController.class).findOne(metadata.getTopicName(), null))
                .withRel("topic"));

        response.addResult(result);
    });

    return response;
}

From source file:com.uber.hoodie.hive.TestUtil.java

private static HoodieCommitMetadata createPartitions(int numberOfPartitions, boolean isParquetSchemaSimple,
        DateTime startFrom, String commitTime) throws IOException, URISyntaxException, InterruptedException {
    startFrom = startFrom.withTimeAtStartOfDay();

    HoodieCommitMetadata commitMetadata = new HoodieCommitMetadata();
    for (int i = 0; i < numberOfPartitions; i++) {
        String partitionPath = dtfOut.print(startFrom);
        Path partPath = new Path(hiveSyncConfig.basePath + "/" + partitionPath);
        fileSystem.makeQualified(partPath);
        fileSystem.mkdirs(partPath);/*from  w w w  . j ava  2  s  .com*/
        List<HoodieWriteStat> writeStats = createTestData(partPath, isParquetSchemaSimple, commitTime);
        startFrom = startFrom.minusDays(1);
        writeStats.forEach(s -> commitMetadata.addWriteStat(partitionPath, s));
    }
    return commitMetadata;
}

From source file:com.uber.hoodie.hive.TestUtil.java

@SuppressWarnings({ "unchecked", "deprecation" })
private static void generateParquetData(Path filePath, boolean isParquetSchemaSimple)
        throws IOException, URISyntaxException, InterruptedException {
    Schema schema = (isParquetSchemaSimple ? SchemaTestUtil.getSimpleSchema()
            : SchemaTestUtil.getEvolvedSchema());
    org.apache.parquet.schema.MessageType parquetSchema = new AvroSchemaConverter().convert(schema);
    BloomFilter filter = new BloomFilter(1000, 0.0001);
    HoodieAvroWriteSupport writeSupport = new HoodieAvroWriteSupport(parquetSchema, schema, filter);
    ParquetWriter writer = new ParquetWriter(filePath, writeSupport, CompressionCodecName.GZIP,
            120 * 1024 * 1024, ParquetWriter.DEFAULT_PAGE_SIZE, ParquetWriter.DEFAULT_PAGE_SIZE,
            ParquetWriter.DEFAULT_IS_DICTIONARY_ENABLED, ParquetWriter.DEFAULT_IS_VALIDATING_ENABLED,
            ParquetWriter.DEFAULT_WRITER_VERSION, fileSystem.getConf());

    List<IndexedRecord> testRecords = (isParquetSchemaSimple ? SchemaTestUtil.generateTestRecords(0, 100)
            : SchemaTestUtil.generateEvolvedTestRecords(100, 100));
    testRecords.forEach(s -> {
        try {//from w ww  .  j  a  v a 2  s.  c  o  m
            writer.write(s);
        } catch (IOException e) {
            fail("IOException while writing test records as parquet" + e.toString());
        }
    });
    writer.close();
}