Example usage for java.lang Iterable forEach

List of usage examples for java.lang Iterable forEach

Introduction

In this page you can find the example usage for java.lang Iterable 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.chevrier.legiondao.boot.Boot.java

public static void main(String[] args) {
    //SpringApplication.run(Boot.class);

    SpringApplication app = new SpringApplication(ConfigJpa.class);
    //app.setLogStartupInfo(false);
    // on la lance
    ConfigurableApplicationContext context = app.run(args);

    PersonnageRepository personnageRepository = context.getBean(PersonnageRepository.class);

    Iterable<Personnage> allPersonnage = personnageRepository.findAll();

    allPersonnage.forEach(perso -> log.info(perso.getNom()));
    System.out.println("Let's inspect the beans provided by Spring Boot:");

    String[] beanNames = context.getBeanDefinitionNames();
    Arrays.sort(beanNames);//from w w w .  java2 s .  co  m
    for (String beanName : beanNames) {
        System.out.println(beanName);
    }
    // fermeture du contexte Spring
    context.close();
}

From source file:Main.java

public static <T> Set<T> toConcurrentSet(Iterable<T> iterable) {
    Set<T> temp = ConcurrentHashMap.newKeySet();
    iterable.forEach(temp::add);
    return temp;/*w w w .  ja v a  2  s .  com*/
}

From source file:Main.java

public static <T> List<T> toConcurrentList(Iterable<T> iterable) {
    List<T> temp = new CopyOnWriteArrayList<>();
    iterable.forEach(temp::add);
    return temp;//w w  w.  ja va 2s. c  o  m
}

From source file:Main.java

public static <T> List<T> toList(Iterable<T> iterable) {
    List<T> temp = new ArrayList<>();
    iterable.forEach(temp::add);
    return temp;//from   w w  w .  j  a  v  a2s.co  m
}

From source file:Main.java

public static <T> Set<T> toSet(Iterable<T> iterable) {
    Collections d;//from w w  w  .  ja v  a 2s .  c o  m
    Set<T> temp = new HashSet<>();
    iterable.forEach(temp::add);
    return temp;
}

From source file:Main.java

public static <T> LinkedHashSet<T> getDuplicates(final Iterable<T> iterable) {
    LinkedHashSet<T> duplicates = new LinkedHashSet<>();
    Set<T> dupeChecker = new LinkedHashSet<>();
    iterable.forEach((m) -> {
        if (!dupeChecker.add(m)) {
            duplicates.add(m);/*from  w  w  w . j a  va2s  .c o m*/
        }
    });
    return duplicates;
}

From source file:org.openlmis.fulfillment.util.Pagination.java

/**
 * Convenience method for getPage(List originalList, Pageable pageable).
 */// ww w.  j ava  2 s .c o  m
public static <T> Page<T> getPage(Iterable<T> data, Pageable pageable) {
    List<T> resultList = new ArrayList<>();
    data.forEach(resultList::add);
    return getPage(resultList, pageable);
}

From source file:com.linecorp.armeria.server.docs.ThriftDocString.java

private static void traverseChildren(ImmutableMap.Builder<String, String> docStrings, String prefix,
        String delimiter, Object node) {
    if (node instanceof Map) {
        @SuppressWarnings("unchecked")
        final Map<String, Object> map = (Map<String, Object>) node;
        final String name = (String) map.get("name");
        final String doc = (String) map.get("doc");
        String childPrefix;/*  w w w  .  jav  a  2s  .  c o  m*/
        if (name != null) {
            childPrefix = (prefix != null ? prefix : "") + delimiter + name;
            if (doc != null) {
                docStrings.put(childPrefix, doc);
            }
        } else {
            childPrefix = prefix;
        }
        map.forEach((key, value) -> traverseChildren(docStrings, childPrefix, DELIM, value));
    } else if (node instanceof Iterable) {
        @SuppressWarnings("unchecked")
        final Iterable<Object> children = (Iterable<Object>) node;
        children.forEach(child -> traverseChildren(docStrings, prefix, DELIM, child));
    }
}

From source file:edu.umd.umiacs.clip.tools.io.AllFiles.java

public static void write(Iterable<?> lines) {
    lines.forEach(System.out::println);
}

From source file:com.bjond.Main.java

/**
*  Given an input stream _in_ to an audit log, the unobfuscated log will be stream to _out_.
* 
* @param in//from w  w w . j a  v  a2s  .c o m
* @param out
* 
* @throws IOException
* @throws SQLException
*/
public static void process(final InputStream in, final OutputStream out) throws IOException, SQLException {
    log.info("Execution begins...");

    // Generate the POSTGRESQL URL form system envirionment variables.
    POSTGRESQL_URL = String.format("jdbc:postgresql://%s:%s/%s", OPENSHIFT_POSTGRESQL_DB_HOST,
            OPENSHIFT_POSTGRESQL_DB_PORT, OPENSHIFT_APP_NAME);

    try (final Connection db = DriverManager.getConnection(POSTGRESQL_URL, OPENSHIFT_POSTGRESQL_DB_USERNAME,
            OPENSHIFT_POSTGRESQL_DB_PASSWORD)) {

        final PrintStream outPrintStream = new PrintStream(out, true, "UTF-8");
        final Reader inReader = new InputStreamReader(in, "UTF-8");
        final Iterable<CSVRecord> records = CSVFormat.DEFAULT.withQuote('\'').parse(inReader);

        log.info("PostgreSQL DB connectiion valid: {}", db.isValid(1000));

        records.forEach(record -> {
            record.iterator().forEachRemaining(e -> {
                try {
                    if (!e.isEmpty()) {
                        final String[] tuple = keyValueSplitter(e);
                        outPrintStream.printf("%s='%s',", tuple[0], resolve(db, tuple[0], tuple[1]));
                    }
                } catch (final Exception exception) {
                    log.error("unexpected error on " + e, exception);
                }
            });

            outPrintStream.printf("%n"); // EOL
        });
    }

    log.info("Execution ends...");
}