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:eu.mihosoft.vrl.v3d.Edge.java

public static List<Vertex> toVertices(List<Edge> edges) {
    return edges.stream().map(e -> e.p1).collect(Collectors.toList());
}

From source file:eu.mihosoft.vrl.v3d.Edge.java

public static List<Vector3d> toPoints(List<Edge> edges) {
    return edges.stream().map(e -> e.p1.pos).collect(Collectors.toList());
}

From source file:com.spotify.heroic.HeroicInteractiveShell.java

public static HeroicInteractiveShell buildInstance(final List<CommandDefinition> commands,
        FileInputStream input) throws Exception {
    final ConsoleReader reader = new ConsoleReader("heroicsh", input, System.out, null);

    final FileHistory history = setupHistory(reader);

    if (history != null) {
        reader.setHistory(history);//from   w  w w . ja  v  a 2 s.c o  m
    }

    reader.setPrompt(String.format("heroic> "));
    reader.addCompleter(
            new StringsCompleter(ImmutableList.copyOf(commands.stream().map((d) -> d.getName()).iterator())));
    reader.setHandleUserInterrupt(true);

    return new HeroicInteractiveShell(reader, commands, history);
}

From source file:de.micromata.genome.jpa.metainf.MetaInfoUtils.java

/**
 * Fill entity metadata.//from w  w w .  j a va 2 s. c  o m
 *
 * @param emgrFac the emgr fac
 * @return the jpa metadata repostory
 */
public static JpaMetadataRepostory fillEntityMetadata(EmgrFactory<?> emgrFac) {
    JpaMetadataRepostory nrepo = new JpaMetadataRepostory();
    Metamodel metamodel = emgrFac.getEntityManagerFactory().getMetamodel();
    Set<ManagedType<?>> mtl = metamodel.getManagedTypes();
    for (ManagedType<?> mt : mtl) {
        EntityMetadata empt = toEntityMetaData(mt);
        nrepo.getEntities().put(empt.getJavaType(), empt);
    }
    resolve(nrepo);
    buildReferences(nrepo);
    List<EntityMetadata> entities = buildSortedEnties(nrepo);
    nrepo.getTableEntities().addAll(entities);

    if (LOG.isDebugEnabled() == true) {
        LOG.debug("Sorted entities: "
                + entities.stream().map((e) -> e.getJavaType().getSimpleName()).collect(Collectors.toList()));
    }
    return nrepo;
}

From source file:delfos.dataset.util.DatasetPrinter.java

private static String actuallyDoTheTable(final List<Item> itemsAllUsersRated, final List<User> users,
        DatasetLoader<? extends Rating> datasetLoader) {
    List<String> columnNames = new ArrayList<>();
    columnNames.add("user\\items");
    columnNames.addAll(/*from   ww  w.  ja  v  a 2s . c o  m*/
            itemsAllUsersRated.stream().map(item -> "Item_" + item.getId()).collect(Collectors.toList()));

    Object[][] data = new Object[users.size()][itemsAllUsersRated.size() + 1];

    DecimalFormat format = new DecimalFormat("0.0000");

    IntStream.range(0, users.size()).forEach(indexUser -> {
        User user = users.get(indexUser);

        data[indexUser][0] = user.toString();

        Map<Integer, ? extends Rating> userRatingsRated = datasetLoader.getRatingsDataset()
                .getUserRatingsRated(user.getId());

        IntStream.range(0, itemsAllUsersRated.size()).forEach(indexItem -> {
            Item item = itemsAllUsersRated.get(indexItem);
            if (userRatingsRated.containsKey(item.getId())) {
                data[indexUser][indexItem + 1] = format
                        .format(userRatingsRated.get(item.getId()).getRatingValue().doubleValue());
            } else {
                data[indexUser][indexItem + 1] = "";
            }
        });
    });

    TextTable textTable = new TextTable(columnNames.toArray(new String[0]), data);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream recordingStream = new PrintStream(baos);
    textTable.printTable(recordingStream, 0);

    return baos.toString();
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static void writeLog(String file, List<LogRecord> records) throws BusinessException {
    try {/*  w  w w.  ja  va  2s . co m*/
        Logger logger = Logger.getAnonymousLogger();
        SimpleFormatter formatter = new SimpleFormatter();
        FileHandler fh = new FileHandler(file, Boolean.TRUE);
        fh.setFormatter(formatter);
        logger.addHandler(fh);
        logger.setUseParentHandlers(false);
        records.stream().forEach((logRecord) -> {
            logger.log(logRecord);
        });
    } catch (IOException | SecurityException ex) {
        Logger.getLogger(BusinessUtils.class.getName()).log(Level.SEVERE, "BusinessUtils.writeLog Exception",
                ex);
        throw new BusinessException(ex);
    }
}

From source file:aiai.ai.launchpad.experiment.ExperimentService.java

private static Map<String, String> toMap(List<ExperimentHyperParams> experimentHyperParams) {
    return experimentHyperParams.stream().collect(Collectors.toMap(ExperimentHyperParams::getKey,
            ExperimentHyperParams::getValues, (a, b) -> b, HashMap::new));
}

From source file:com.tascape.qa.th.android.comm.Adb.java

private static void loadAllSerials() {
    SERIALS.clear();/*from  w w w. j a va2 s  .c o  m*/
    String serials = SystemConfiguration.getInstance().getProperty(SYSPROP_SERIALS);
    if (null != serials) {
        LOG.info("Use specified devices from system property {}={}", SYSPROP_SERIALS, serials);
        SERIALS.addAll(Lists.newArrayList(serials.split(",")));
    } else {
        CommandLine cmdLine = new CommandLine(ADB);
        cmdLine.addArgument("devices");
        LOG.debug("{}", cmdLine.toString());
        List<String> output = new ArrayList<>();
        Executor executor = new DefaultExecutor();
        executor.setStreamHandler(new ESH(output));
        try {
            if (executor.execute(cmdLine) != 0) {
                throw new RuntimeException(cmdLine + " failed");
            }
        } catch (IOException ex) {
            throw new RuntimeException(cmdLine + " failed", ex);
        }
        output.stream().filter((line) -> (line.endsWith("device"))).forEach((line) -> {
            String s = line.split("\\t")[0];
            LOG.info("serial {}", s);
            SERIALS.add(s);
        });
    }
    if (SERIALS.isEmpty()) {
        throw new RuntimeException("No device detected.");
    }
}

From source file:com.tascape.qa.th.android.comm.Adb.java

private static void loadSerialProductMap() {
    SERIAL_PRODUCT.clear();/*from  w  w  w.  j  a va2  s  . c  o m*/
    String serials = SystemConfiguration.getInstance().getProperty(SYSPROP_SERIALS);
    if (null != serials) {
        LOG.info("Use specified devices from system property {}={}", SYSPROP_SERIALS, serials);
        Lists.newArrayList(serials.split(",")).forEach(s -> SERIAL_PRODUCT.put(s, "na"));
    } else {
        CommandLine cmdLine = new CommandLine(ADB);
        cmdLine.addArgument("devices");
        cmdLine.addArgument("-l");
        LOG.debug("{}", cmdLine.toString());
        List<String> output = new ArrayList<>();
        Executor executor = new DefaultExecutor();
        executor.setStreamHandler(new ESH(output));
        try {
            if (executor.execute(cmdLine) != 0) {
                throw new RuntimeException(cmdLine + " failed");
            }
        } catch (IOException ex) {
            throw new RuntimeException(cmdLine + " failed", ex);
        }
        output.stream().map(line -> StringUtils.split(line, " ", 3))
                .filter(ss -> ss.length == 3 && ss[1].equals("device")).forEach(ss -> {
                    LOG.info("device {} -> {}", ss[0], ss[2]);
                    SERIAL_PRODUCT.put(ss[0], ss[2]);
                });
    }
    if (SERIAL_PRODUCT.isEmpty()) {
        throw new RuntimeException("No device detected.");
    }
    SERIALS.addAll(SERIAL_PRODUCT.keySet());
}

From source file:com.wrmsr.wava.transform.Transforms.java

public static com.wrmsr.wava.core.unit.Function eliminateUnreferencedLocals(
        com.wrmsr.wava.core.unit.Function function) {
    LocalAnalysis.Entry la = LocalAnalysis.analyze(function.getBody()).get(function.getBody());
    List<Index> indices = new ArrayList<>(Sets.union(la.getLocalGets(), la.getLocalPuts()));
    Collections.sort(indices);//  www  .ja va2 s . co m
    Locals locals = Locals
            .of(function.getLocals().getList().stream().filter(l -> indices.contains(l.getIndex()))
                    .map(l -> ImmutablePair.of(l.getName(), l.getType())).collect(toImmutableList()));
    Map<Index, Index> indexMap = enumerate(indices.stream())
            .collect(toImmutableMap(i -> i.getItem(), i -> Index.of(i.getIndex())));
    return new com.wrmsr.wava.core.unit.Function(function.getName(), function.getResult(),
            function.getArgCount(), locals, remapLocals(function.getBody(), indexMap));
}