Example usage for java.util List stream

List of usage examples for java.util List stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:de.peran.DependencyReadingStarter.java

public static void main(final String[] args) throws ParseException, FileNotFoundException {
    final Options options = OptionConstants.createOptions(OptionConstants.FOLDER, OptionConstants.STARTVERSION,
            OptionConstants.ENDVERSION, OptionConstants.OUT);

    final CommandLineParser parser = new DefaultParser();
    final CommandLine line = parser.parse(options, args);

    final File projectFolder = new File(line.getOptionValue(OptionConstants.FOLDER.getName()));

    final File dependencyFile;
    if (line.hasOption(OptionConstants.OUT.getName())) {
        dependencyFile = new File(line.getOptionValue(OptionConstants.OUT.getName()));
    } else {/*from w  ww .  j av  a 2s  .c o  m*/
        dependencyFile = new File("dependencies.xml");
    }

    File outputFile = projectFolder.getParentFile();
    if (outputFile.isDirectory()) {
        outputFile = new File(projectFolder.getParentFile(), "ausgabe.txt");
    }

    LOG.debug("Lese {}", projectFolder.getAbsolutePath());
    final VersionControlSystem vcs = VersionControlSystem.getVersionControlSystem(projectFolder);

    System.setOut(new PrintStream(outputFile));
    // System.setErr(new PrintStream(outputFile));

    final DependencyReader reader;
    if (vcs.equals(VersionControlSystem.SVN)) {
        final String url = SVNUtils.getInstance().getWCURL(projectFolder);
        final List<SVNLogEntry> entries = getSVNCommits(line, url);
        LOG.debug("SVN commits: "
                + entries.stream().map(entry -> entry.getRevision()).collect(Collectors.toList()));
        reader = new DependencyReader(projectFolder, url, dependencyFile, entries);
    } else if (vcs.equals(VersionControlSystem.GIT)) {
        final List<GitCommit> commits = getGitCommits(line, projectFolder);
        reader = new DependencyReader(projectFolder, dependencyFile, commits);
        LOG.debug("Reader initalized");
    } else {
        throw new RuntimeException("Unknown version control system");
    }
    reader.readDependencies();
}

From source file:Main.java

public static void main(String[] args) {
    List<Person> roster = createRoster();

    System.out.println("Names of male members with collect operation: ");
    List<String> namesOfMaleMembersCollect = roster.stream().filter(p -> p.getGender() == Person.Sex.MALE)
            .map(p -> p.getName()).collect(Collectors.toList());

    namesOfMaleMembersCollect.stream().forEach(p -> System.out.println(p));

}

From source file:pt.souplesse.spark.Server.java

public static void main(String[] args) {
    EntityManagerFactory factory = Persistence.createEntityManagerFactory("guestbook");
    EntityManager manager = factory.createEntityManager();
    JinqJPAStreamProvider streams = new JinqJPAStreamProvider(factory);
    get("/messages", (req, rsp) -> {
        rsp.type("application/json");
        return gson.toJson(streams.streamAll(manager, Message.class).collect(Collectors.toList()));
    });/*from  w  w w.  jav  a 2 s  . co  m*/
    post("/messages", (req, rsp) -> {
        try {
            Message msg = gson.fromJson(req.body(), Message.class);
            if (StringUtils.isBlank(msg.getMessage()) || StringUtils.isBlank(msg.getName())) {
                halt(400);
            }
            manager.getTransaction().begin();
            manager.persist(msg);
            manager.getTransaction().commit();
        } catch (JsonSyntaxException e) {
            halt(400);
        }
        rsp.type("application/json");
        return gson.toJson(streams.streamAll(manager, Message.class).collect(Collectors.toList()));
    });
    get("/comments", (req, rsp) -> {
        rsp.type("application/json");
        Map<String, List<Body>> body = new HashMap<>();
        try (CloseableHttpClient client = create().build()) {
            String url = String.format("https://api.github.com/repos/%s/events", req.queryMap("repo").value());
            log.info(url);
            body = client.execute(new HttpGet(url), r -> {
                List<Map<String, Object>> list = gson.fromJson(EntityUtils.toString(r.getEntity()), List.class);
                Map<String, List<Body>> result = new HashMap<>();
                list.stream().filter(m -> m.getOrDefault("type", "").equals("IssueCommentEvent"))
                        .map(m -> new Body(((Map<String, String>) m.get("actor")).get("login"),
                                ((Map<String, Map<String, String>>) m.get("payload")).get("comment")
                                        .get("body")))
                        .forEach(b -> result.compute(b.getLogin(), (k, v) -> v == null ? new ArrayList<>()
                                : Lists.asList(b, v.toArray(new Body[v.size()]))));
                return result;
            });
        } catch (IOException e) {
            log.error(null, e);
            halt(400, e.getMessage());
        }
        return gson.toJson(body);
    });
}

From source file:Main.java

public static void main(String[] args) {
    List<Person> roster = createRoster();
    ConcurrentMap<Person.Sex, List<Person>> byGenderParallel = roster.parallelStream()
            .collect(Collectors.groupingByConcurrent(Person::getGender));

    List<Map.Entry<Person.Sex, List<Person>>> byGenderList = new ArrayList<>(byGenderParallel.entrySet());

    System.out.println("Group members by gender:");
    byGenderList.stream().forEach(e -> {
        System.out.println("Gender: " + e.getKey());
        e.getValue().stream().map(Person::getName).forEach(f -> System.out.println(f));
    });//  w ww  .  jav  a 2s  .c  o  m

}

From source file:Main.java

public static void main(String[] args) {
    List<Trade> trades = TradeUtil.createTrades();

    Function<Trade, Integer> doubledQty = t -> {
        t.setQuantity(t.getQuantity() * 2);
        return t.getQuantity();
    };//from w  ww  . ja va2  s.c  o m

    long x = trades.stream().map(doubledQty).filter(qty -> qty > 15).count();

    System.out.println(x);

}

From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java

public static void main(String[] args) throws IOException {
    Path storeDir = Paths.get(args[0]);
    try (ProjectUsageStore store = new ProjectUsageStore(storeDir)) {
        List<ICoReTypeName> types = new ArrayList<>(store.getAllTypes());
        types.sort(new TypeNameComparator());

        System.out.println(//  ww w.  j  ava  2s  .  com
                types.stream().filter(t -> t.getIdentifier().contains("KaVE.")).collect(Collectors.toList()));
        //         if (args.length == 1 || args[1].equals("countFilteredUsages")) {
        //            countFilteredUsages(types, store);
        //         } else if (args[1].equals("countRecvCallSites")) {
        //            countRecvCallSites(types, store);
        //         }
        // methodPropabilities(types, store);
    }

}

From source file:com.khartec.waltz.jobs.sample.CapabilityGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<String> lines = readLines(CapabilityGenerator.class.getResourceAsStream("/capabilities.csv"));

    System.out.println("Deleting existing Caps's");
    dsl.deleteFrom(CAPABILITY).execute();

    List<CapabilityRecord> records = lines.stream().skip(1).map(line -> line.split("\t"))
            .filter(cells -> cells.length == 4).map(cells -> {
                CapabilityRecord record = new CapabilityRecord();
                record.setId(longVal(cells[0]));
                record.setParentId(longVal(cells[1]));
                record.setName(cells[2]);
                record.setDescription(cells[3]);

                System.out.println(record);
                return record;
            }).collect(Collectors.toList());

    System.out.println("Inserting new Caps's");
    dsl.batchInsert(records).execute();//from   w  w  w . j  a v  a  2  s  . co  m

    System.out.println("Done");

}

From source file:com.doctor.java8.GroupingTheData.java

public static void main(String[] args) {
    List<Person> persons = Arrays.asList(new Person("doctor", "man", "address-1"),
            new Person("doctor who ", "man", "address-1"), new Person("doctor me", "woman", "address-2"));
    Map<String, List<Person>> map = persons.stream().collect(Collectors.groupingBy(Person::getSex));
    System.out.println(map);/*from  ww  w  . ja va2 s . c  om*/

    Map<String, Map<String, List<Person>>> map2 = persons.stream()
            .collect(Collectors.groupingBy(Person::getSex, Collectors.groupingBy(Person::getAddress)));
    System.out.println(map2);
}

From source file:com.khartec.waltz.jobs.sample.OrgUnitGenerator.java

public static void main(String[] args) throws IOException {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv"));

    System.out.println("Deleting existing OU's");
    dsl.deleteFrom(ORGANISATIONAL_UNIT).execute();

    List<OrganisationalUnitRecord> records = lines.stream().skip(1)
            .map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4)
            .map(cells -> {/*  w  ww  .  j  a  va  2 s. c om*/
                OrganisationalUnitRecord record = new OrganisationalUnitRecord();
                record.setId(longVal(cells[0]));
                record.setParentId(longVal(cells[1]));
                record.setName(cells[2]);
                record.setDescription(cells[3]);
                record.setUpdatedAt(new Timestamp(System.currentTimeMillis()));

                System.out.println(record);
                return record;
            }).collect(Collectors.toList());

    System.out.println("Inserting new OU's");
    dsl.batchInsert(records).execute();

    System.out.println("Done");

}

From source file:com.rdsic.pileconstructionmanagement.test.Test.java

public static void main(String[] args) {
    String sql = "select * from user";

    List<Map<String, Object>> list = (ArrayList) GenericHql.INSTANCE.querySQL(sql, 20);

    if (!list.isEmpty()) {
        System.out.println("cnt:" + list.size());

        JSONObject r = new JSONObject();
        r.put("items", list);

        System.out.println(r.toString());

        list.stream().map((item) -> {
            System.out.println("RECORD");
            return item;
        }).forEach((item) -> {/*from   w w w. j ava 2s .com*/

            for (String k : item.keySet()) {
                JSONObject j = new JSONObject(item);
                System.out.println(j.toString());

                System.out.println(StringUtils.rightPad(k, 20, " ") + item.get(k).toString());
            }
        });
    }
    System.exit(0);
}