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:alfio.util.Validator.java

private static boolean containsAllRequiredTranslations(EventModification eventModification,
        List<EventModification.AdditionalServiceText> descriptions) {
    Optional<EventModification> optional = Optional.ofNullable(eventModification);
    return !optional.isPresent() || optional.map(e -> ContentLanguage.findAllFor(e.getLocales()))
            .filter(l -> l.stream().allMatch(
                    l1 -> descriptions.stream().anyMatch(d -> d.getLocale().equals(l1.getLanguage()))))
            .isPresent();//from   w  w  w . j  a  v  a  2  s  .  co m
}

From source file:eu.itesla_project.modules.validation.OverloadValidationTool.java

private static void writeCsv(Set<String> contingencyIds,
        Map<String, Map<String, OverloadStatus>> statusPerContingencyPerCase, Path outputDir)
        throws IOException {
    try (BufferedWriter writer = Files.newBufferedWriter(outputDir.resolve("comparison.csv"),
            StandardCharsets.UTF_8)) {
        writer.write("base case");
        for (String contingencyId : contingencyIds) {
            writer.write(CSV_SEPARATOR);
            writer.write(contingencyId + " load flow");
            writer.write(CSV_SEPARATOR);
            writer.write(contingencyId + " offline rule");
        }//from  w  w  w  .  j a  v a2 s  .c  o  m
        writer.newLine();

        for (Map.Entry<String, Map<String, OverloadStatus>> e : statusPerContingencyPerCase.entrySet()) {
            String baseCaseName = e.getKey();
            Map<String, OverloadStatus> statusPerContingency = e.getValue();
            writer.write(baseCaseName);
            for (String contingencyId : contingencyIds) {
                OverloadStatus overloadStatus = statusPerContingency.get(contingencyId);
                writer.write(CSV_SEPARATOR);
                writer.write(Boolean.toString(overloadStatus.isLfOk()));
                writer.write(CSV_SEPARATOR);
                writer.write(Boolean.toString(overloadStatus.isOfflineRuleOk()));
            }
            writer.newLine();
        }
    }

    List<String> categories = Arrays.asList("OK_OK", "NOK_NOK", "OK_NOK", "NOK_OK");

    Map<String, Map<String, AtomicInteger>> synthesisPerContingency = new HashMap<>();
    for (String contingencyId : contingencyIds) {
        synthesisPerContingency.put(contingencyId,
                categories.stream().collect(Collectors.toMap(Function.identity(), e -> new AtomicInteger())));
    }
    for (Map.Entry<String, Map<String, OverloadStatus>> e : statusPerContingencyPerCase.entrySet()) {
        Map<String, OverloadStatus> statusPerContingency = e.getValue();
        for (String contingencyId : contingencyIds) {
            OverloadStatus overloadStatus = statusPerContingency.get(contingencyId);
            synthesisPerContingency.get(contingencyId).get(
                    okToString(overloadStatus.isLfOk()) + "_" + okToString(overloadStatus.isOfflineRuleOk()))
                    .incrementAndGet();
        }
    }

    try (BufferedWriter writer = Files.newBufferedWriter(outputDir.resolve("synthesis.csv"),
            StandardCharsets.UTF_8)) {
        writer.write("contingency");
        for (String c : categories) {
            writer.write(CSV_SEPARATOR);
            writer.write(c);
        }
        writer.newLine();
        for (Map.Entry<String, Map<String, AtomicInteger>> e : synthesisPerContingency.entrySet()) {
            String contingencyId = e.getKey();
            Map<String, AtomicInteger> count = e.getValue();
            writer.write(contingencyId);
            for (String c : categories) {
                writer.write(CSV_SEPARATOR);
                writer.write(Integer.toString(count.get(c).get()));
            }
            writer.newLine();
        }
    }
}

From source file:com.github.anba.es6draft.util.Resources.java

private static Iterable<String> nonEmpty(List<?> c) {
    return () -> c.stream().filter(x -> (x != null && !x.toString().isEmpty())).map(Object::toString)
            .iterator();/*from   ww w.j  av a  2  s .  c  om*/
}

From source file:com.twosigma.beakerx.table.serializer.TableDisplayDeSerializer.java

@NotNull
private static Object handleIndex(JsonNode n, ObjectMapper mapper, List<List<?>> values, List<String> columns,
        List<String> classes) throws IOException {
    List<String> indexName = (List<String>) mapper.readValue(n.get(INDEX_NAME).toString(), List.class);
    boolean standardIndex = indexName.size() == 1 && indexName.get(0).equals(INDEX);
    if (standardIndex) {
        columns.remove(0);/*from w w  w  . j  a v  a  2  s.c o  m*/
        classes.remove(0);
        for (List<?> v : values) {
            v.remove(0);
        }
    } else {
        columns.set(0, join(", ", indexName.stream().map(TableDisplayDeSerializer::convertNullToIndexName)
                .collect(Collectors.toList())));
    }
    TableDisplay td = new TableDisplay(values, columns, classes);
    if (!standardIndex) {
        td.setHasIndex("true");
    }
    return td;
}

From source file:library.entry.Main.java

private static void viewbooks(List<Book> books) {
    if (books.isEmpty()) {
        ConsoleHelper.printMessage("");
        ConsoleHelper.printMessage("==== No books available ====");
        return;//w w  w  . j a va 2s. com
    }
    while (true) {
        ConsoleHelper.printMessage("");
        ConsoleHelper.printMessage("To view details enter the book ID, to return press <Enter>");
        ConsoleHelper.printMessage("");
        books.stream().forEach(o -> ConsoleHelper.printBookSelection(o.getId(), o.getTitle()));
        ConsoleHelper.printMessage("");
        ConsoleHelper.printPrompt("Book ID");
        Integer selectedId = ConsoleHelper.getInt(true);
        if (selectedId == null) {
            break;
        } else {
            books.stream().filter(b -> b.getId() == selectedId).forEach(b -> {
                ConsoleHelper.printMessage(String.format("ID: %s", "" + b.getId()), 1);
                ConsoleHelper.printMessage(String.format("Title: %s", b.getTitle()), 1);
                ConsoleHelper.printMessage(String.format("Author: %s", b.getAuthor()), 1);
                ConsoleHelper.printMessage(String.format("Description: %s", b.getDescription()), 1);
            });
        }
    }
}

From source file:ai.grakn.graql.GraqlShell.java

private static String loadQuery(String filePath) throws IOException {
    List<String> lines = Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8);
    return lines.stream().collect(joining("\n"));
}

From source file:com.jaredrummler.android.devices.Main.java

private static void writeJavaSwitchStatement(List<String[]> devices) throws IOException {
    StringBuilder sb = new StringBuilder();
    Map<String, Set<String>> deviceMap = new TreeMap<>((o1, o2) -> {
        return o1.compareToIgnoreCase(o2);
    });/*from   w  w  w. ja v a2s  .c o  m*/

    for (String name : POPULAR_DEVICES) {
        List<String> list = new ArrayList<>();
        Set<String> codenames = new HashSet<>();
        devices.stream().filter(arr -> arr[1].equals(name)).forEach(arr -> {
            list.add(arr[2]);
        });
        Collections.sort(list);
        codenames.addAll(list);
        deviceMap.put(name, codenames);
    }

    // TODO: Use JavaPoet and create a working class.
    sb.append("public static String getDeviceName(String codename, String fallback) {\n");
    sb.append("  switch (codename) {\n");
    for (Map.Entry<String, Set<String>> entry : deviceMap.entrySet()) {
        Set<String> codenames = entry.getValue();
        for (String codename : codenames) {
            sb.append("    case \"" + codename + "\":\n");
        }
        sb.append("      return \"" + entry.getKey() + "\";\n");
    }
    sb.append("    default:\n");
    sb.append("      return fallback;\n\t}\n}");

    System.out.println(sb.toString());
    new File("json").mkdirs();
    FileUtils.write(new File("json/gist.txt"), sb.toString());
}

From source file:net.minecraftforge.fml.relauncher.libraries.LibraryManager.java

public static List<Artifact> flattenLists(File mcDir) {
    List<Artifact> merged = new ArrayList<>();
    for (ModList list : ModList.getBasicLists(mcDir)) {
        for (Artifact art : list.flatten()) {
            Optional<Artifact> old = merged.stream().filter(art::matchesID).findFirst();
            if (!old.isPresent()) {
                merged.add(art);//from  ww w. j a  v  a 2s.  c om
            } else if (old.get().getVersion().compareTo(art.getVersion()) < 0) {
                merged.add(merged.indexOf(old.get()), art);
                merged.remove(old.get());
            }
        }
    }
    return merged;
}

From source file:org.eclipse.sw360.datahandler.common.SW360Utils.java

public static <T> Map<String, T> putReleaseNamesInMap(Map<String, T> map, List<Release> releases) {
    if (map == null || releases == null) {
        return Collections.emptyMap();
    }//  ww  w . jav a2  s .  c o  m
    Map<String, T> releaseNamesMap = new HashMap<>();
    releases.stream().forEach(r -> releaseNamesMap.put(printName(r), map.get(r.getId())));
    return releaseNamesMap;
}

From source file:org.eclipse.sw360.datahandler.common.SW360Utils.java

public static <T> Map<String, T> putProjectNamesInMap(Map<String, T> map, List<Project> projects) {
    if (map == null || projects == null) {
        return Collections.emptyMap();
    }/*from  w  w w .ja  v a2  s.co m*/
    Map<String, T> projectNamesMap = new HashMap<>();
    projects.stream().forEach(p -> projectNamesMap.put(printName(p), map.get(p.getId())));
    return projectNamesMap;
}