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:com.netflix.spinnaker.halyard.cli.services.v1.ResponseUnwrapper.java

private static void formatProblemSet(ProblemSet problemSet) {
    if (problemSet == null || problemSet.isEmpty()) {
        return;//from   ww  w  .  ja  v a 2  s. c  o  m
    }

    AnsiSnippet snippet = new AnsiSnippet("\r").setErase(AnsiErase.ERASE_LINE);
    AnsiPrinter.err.print(snippet.toString());

    Map<String, List<Problem>> locationGroup = problemSet.groupByLocation();
    for (Entry<String, List<Problem>> entry : locationGroup.entrySet()) {

        AnsiUi.problemLocation(entry.getKey());
        for (Problem problem : entry.getValue()) {
            Severity severity = problem.getSeverity();
            String message = problem.getMessage();
            String remediation = problem.getRemediation();
            List<String> options = problem.getOptions();

            switch (severity) {
            case FATAL:
            case ERROR:
                AnsiUi.error(message);
                break;
            case WARNING:
                AnsiUi.warning(message);
                break;
            default:
                throw new RuntimeException("Unknown severity level " + severity);
            }

            if (remediation != null && !remediation.isEmpty()) {
                AnsiUi.remediation(remediation);
            }

            if (options != null && !options.isEmpty()) {
                AnsiUi.remediation("Options include: ");
                options.forEach(AnsiUi::listRemediation);
            }

            // Newline between errors
            AnsiUi.raw("");
        }
    }
}

From source file:cz.lbenda.dataman.db.DbStructureFactory.java

public static DatabaseStructureType createXMLDatabaseStructure(List<CatalogDesc> catalogs) {
    cz.lbenda.dataman.schema.dbstructure.ObjectFactory of = new cz.lbenda.dataman.schema.dbstructure.ObjectFactory();
    DatabaseStructureType databaseStructureType = of.createDatabaseStructureType();
    Map<TableDesc, TableType> tableTypeForTableDesc = new HashMap<>();
    Map<ColumnDesc, ColumnType> columnTypeForColumnDesc = new HashMap<>();

    catalogs.forEach(catalogDesc -> {
        CatalogType catalogType = of.createCatalogType();
        catalogType.setName(catalogDesc.getName());
        databaseStructureType.getCatalog().add(catalogType);
        catalogDesc.getSchemas().forEach(schemaDesc -> {
            SchemaType schemaType = of.createSchemaType();
            schemaType.setName(schemaDesc.getName());
            catalogType.getSchema().add(schemaType);
            schemaDesc.getTables().forEach(tableDesc -> {
                TableType tableType = of.createTableType();
                tableTypeForTableDesc.put(tableDesc, tableType);
                tableType.setId(UUID.randomUUID().toString());
                tableType.setName(tableDesc.getName());
                tableType.setTableType(tableDesc.getTableType().name());
                schemaType.getTable().add(tableType);
                tableDesc.getColumns().forEach(columnDesc -> {
                    ColumnType columnType = of.createColumnType();
                    columnTypeForColumnDesc.put(columnDesc, columnType);
                    columnType.setId(UUID.randomUUID().toString());
                    columnType.setName(columnDesc.getName());
                    columnType.setLabel(columnDesc.getLabel());
                    columnType.setAutoincrement(columnDesc.isAutoincrement());
                    columnType.setNullable(columnDesc.isNullable());
                    columnType.setDataType(columnTypeToDataTypeType(columnDesc.getDataType()));
                    columnType.setGenerated(columnDesc.isGenerated());
                    columnType.setIsPK(columnDesc.isPK());
                    columnType.setSize(columnDesc.getSize());
                    columnType.setScale(columnDesc.getScale());
                    columnType.setDefaultValue(columnDesc.getDefaultValue());
                    tableType.getColumn().add(columnType);
                });/*ww w .j av a2  s . c  o  m*/
            });
        });
    });

    catalogs.forEach(catalogDesc -> catalogDesc.getSchemas().forEach(
            schemaDesc -> schemaDesc.getTables().forEach(tableDesc -> tableDesc.getForeignKeys().stream()
                    .filter(foreignKey -> foreignKey.getSlaveTable() == tableDesc).forEach(foreignKey -> {
                        ForeignKeyType foreignKeyType = of.createForeignKeyType();
                        foreignKeyType.setName(foreignKey.getName());
                        foreignKeyType.setDeleteRule(foreignKey.getDeleteRule());
                        foreignKeyType.setUpdateRule(foreignKey.getUpdateRule());

                        foreignKeyType.setMasterTable(tableTypeForTableDesc.get(foreignKey.getMasterTable()));
                        ForeignKeyColumnType masterColumn = of.createForeignKeyColumnType();
                        masterColumn.setColumn(columnTypeForColumnDesc.get(foreignKey.getMasterColumn()));
                        foreignKeyType.getMasterColumn().add(masterColumn);
                        ForeignKeyColumnType slaveColumn = of.createForeignKeyColumnType();
                        slaveColumn.setColumn(columnTypeForColumnDesc.get(foreignKey.getSlaveColumn()));
                        foreignKeyType.getSlaveColumn().add(slaveColumn);

                        tableTypeForTableDesc.get(tableDesc).getForeignKey().add(foreignKeyType);
                    }))));
    return databaseStructureType;
}

From source file:HSqlManager.java

public static void commonClusterNewPhages(Connection connection, int bps) throws SQLException, IOException,
        ClassNotFoundException, IllegalAccessException, InstantiationException {
    Connection db = connection;/*from   ww w  .j av a  2  s. c o  m*/
    String base = new File("").getAbsolutePath();
    db.setAutoCommit(false);
    PreparedStatement st = db.prepareStatement("UPDATE Primerdb.Primers SET CommonP = False,"
            + " UniqueP = False" + " WHERE Cluster = ? and " + "Strain = ? and Sequence = ? and Bp =?");
    Statement stat = db.createStatement();
    if (newPhages != null) {
        List<String[]> phages = newPhages;
        phages.forEach(x -> {
            try {
                CSV.writeDataCSV(x[0], Fasta.process(x[0], bps), bps);
                CSV.writeDataCSV(x[0], Fasta.processPrimers(x[0], bps), bps);
            } catch (IOException e) {
                e.printStackTrace();
            }
            Set<CharSequence> primers = new HashSet<>();
            try {
                ResultSet rs = stat.executeQuery(
                        "SELECT * FROM Primerdb.Primers WHERE" + " Sequence = '" + x[1] + "' and Clusters = '"
                                + x[2] + "' and CommonP = True" + "and Bp =" + Integer.valueOf(bps));
                while (rs.next()) {
                    primers.add((CharSequence) rs.getString("Sequence"));
                }
                primers.removeAll(CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + x[0] + ".csv"));
                if (primers.size() != 0) {
                    primers.forEach(y -> {
                        try {
                            //finish update
                            st.setString(1, x[1]);
                            st.setString(2, x[2]);
                            st.setString(3, y.toString());
                            st.setInt(4, bps);
                            st.addBatch();
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    });
                    st.executeBatch();
                    db.commit();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        });
    }
    System.out.println("Common Updated");
    st.close();
}

From source file:com.marand.thinkmed.medications.dto.report.TherapyDayReportUtils.java

private static String getQuantityDisplay(final SimpleTherapyDto order) {
    if (order instanceof ConstantSimpleTherapyDto) {
        return order.getQuantityDisplay();
    } else {/*  w  w  w . j  av a  2s .c o  m*/
        final StringBuilder strBuilder = new StringBuilder();
        final List<TimedSimpleDoseElementDto> timedDoseElements = ((VariableSimpleTherapyDto) order)
                .getTimedDoseElements().stream().filter(element -> element.getQuantityDisplay() != null)
                .collect(Collectors.toList());

        final boolean simpleVariable = timedDoseElements.get(0).getDate() == null;

        if (simpleVariable) {
            timedDoseElements.forEach(element -> strBuilder.append(
                    combineTimeAndQuantity(null, element.getTimeDisplay(), element.getQuantityDisplay())));
        } else {
            Collections.sort(timedDoseElements, Comparator.comparing(TimedSimpleDoseElementDto::getDate));

            DateTime currentDate = null;
            for (final TimedSimpleDoseElementDto timedDoseElement : timedDoseElements) {
                if (timedDoseElement.getDate().equals(currentDate)) {
                    strBuilder.append(combineTimeAndQuantity(null, timedDoseElement.getTimeDisplay(),
                            timedDoseElement.getQuantityDisplay()));
                } else {
                    strBuilder.append(combineTimeAndQuantity(timedDoseElement.getDate(),
                            timedDoseElement.getTimeDisplay(), timedDoseElement.getQuantityDisplay()));

                    currentDate = timedDoseElement.getDate();
                }
            }
        }

        return strBuilder.toString();
    }
}

From source file:org.fcrepo.camel.ldpath.ClientFactory.java

/**
 * Create a linked data client suitable for use with a Fedora Repository.
 * @param authScope the authentication scope
 * @param credentials the credentials//from  w w w  .  jav  a 2s  .c o m
 * @param endpoints additional endpoints to enable on the client
 * @param providers additional providers to enable on the client
 * @return a configuration for use with an LDClient
 */
public static ClientConfiguration createClient(final AuthScope authScope, final Credentials credentials,
        final List<Endpoint> endpoints, final List<DataProvider> providers) {

    final ClientConfiguration client = new ClientConfiguration();

    if (credentials != null && authScope != null) {
        final CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(authScope, credentials);
        client.setHttpClient(HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
                .useSystemProperties().build());
    }

    // manually add default Providers and Endpoints
    client.addProvider(new LinkedDataProvider());
    client.addProvider(new CacheProvider());
    client.addProvider(new RegexUriProvider());
    client.addProvider(new SPARQLProvider());
    client.addEndpoint(new LinkedDataEndpoint());

    // add any injected endpoints/providers
    endpoints.forEach(client::addEndpoint);
    providers.forEach(client::addProvider);

    return client;
}

From source file:delfos.rs.trustbased.WeightedGraph.java

public static final AdjMatrixEdgeWeightedDigraph inverseOfEdgeValue(
        AdjMatrixEdgeWeightedDigraph distanceGraph) {

    AdjMatrixEdgeWeightedDigraph weightGraph = new AdjMatrixEdgeWeightedDigraph(distanceGraph.V());

    List<DirectedEdge> allEdges = IntStream.range(0, distanceGraph.V()).boxed().map(vertex -> {
        Iterable<DirectedEdge> iterator = distanceGraph.adj(vertex);
        ArrayList<DirectedEdge> listOfEdges = new ArrayList<>();
        for (DirectedEdge edge : iterator) {
            listOfEdges.add(edge);//from  www. j  a  v  a 2s . c o  m
        }
        return listOfEdges;
    }).flatMap(listOfEdges -> listOfEdges.stream()).collect(Collectors.toList());

    List<DirectedEdge> allEdgesConverted = allEdges.stream().map(edge -> {
        final double weight = edge.weight();

        double distance = 1 / weight;

        if (weight == 0) {
            distance = Double.POSITIVE_INFINITY;
        }

        return new DirectedEdge(edge.from(), edge.to(), distance);
    }).collect(Collectors.toList());

    allEdgesConverted.forEach(edge -> weightGraph.addEdge(edge));
    return weightGraph;
}

From source file:com.mec.DAO.ConexionesEscuelas.ConexionesDAO.java

private List<Conexiones> lazyInit(List<Conexiones> conexiones) {
    conexiones.forEach(c -> {
        Hibernate.initialize(c.getConexionTipo());
        Hibernate.initialize(c.getMovimiento());
        Hibernate.initialize(c.getProveedor());
    });/*  www. ja  va  2 s.com*/
    return conexiones;
}

From source file:com.grayfox.server.test.dao.jdbc.UtilJdbcDao.java

public void savePois(List<Poi> pois) {
    pois.forEach(poi -> savePoi(poi));
}

From source file:info.lejin.raphael.controller.FrontController.java

@RequestMapping(method = RequestMethod.GET, path = "admin/home")
public ModelAndView getUsers() {
    ModelAndView view = new ModelAndView("admin/index");
    List<User> userlist = userDao.list();
    userlist.forEach(user -> System.out.println(user.getUsername()));
    view.addObject("users", userlist);
    return view;//ww w  .  j  a  v  a  2 s  .  com
}

From source file:com.mec.DAO.Postgre.LocalidadPostgreDAO.java

private List<LocalidadTipo> lazyInit(List<LocalidadTipo> localidades) {
    localidades.forEach((l) -> {
        Hibernate.initialize(l.getDepartamento());
    });//from   w  ww  . j a  v  a 2  s.  co m
    return localidades;
}