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:dk.dma.db.cassandra.CassandraConnection.java

/**
 * Creates a new Cassandra connection. The connection is not yet connected but must be started via {@link #start()}
 * and to close it use {@link #stop()}/* ww w .j  a  v a 2s .  c o  m*/
 * 
 * @param keyspace
 *            the name of the keyspace
 * @param connectionPoints
 *            a comma-separated list of connection points expressed as <hostname>[:<port>]
 * @return a new connection
 */
public static CassandraConnection create(String keyspace, List<String> connectionPoints) {
    Cluster cluster;

    if (seedsContainPortNumbers(connectionPoints)) {
        Collection<InetSocketAddress> cassandraSeeds = new ArrayList<>();
        connectionPoints.forEach(cp -> cassandraSeeds.add(connectionPointToInetAddress(cp)));
        cluster = Cluster.builder().addContactPointsWithPorts(cassandraSeeds)
                .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(1000 * 60)).build();
    } else {
        cluster = Cluster.builder().addContactPoints(connectionPoints.toArray(new String[0]))
                .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(1000 * 60)).build();
    }

    return new CassandraConnection(cluster, keyspace);
}

From source file:io.kamax.mxisd.backend.ldap.LdapBackend.java

public static String buildOrQuery(String value, List<String> attributes) {
    if (attributes.size() < 1) {
        throw new IllegalArgumentException();
    }//w  ww. j  a v a 2 s .  com

    StringBuilder builder = new StringBuilder();
    builder.append("(|");
    attributes.forEach(s -> {
        builder.append("(");
        builder.append(s).append("=").append(value).append(")");
    });
    builder.append(")");
    return builder.toString();
}

From source file:com.netflix.spinnaker.halyard.cli.ui.v1.AnsiFormatUtils.java

public static String format(Provider provider) {
    AnsiStoryBuilder resultBuilder = new AnsiStoryBuilder();
    AnsiParagraphBuilder paragraph = resultBuilder.addParagraph();

    paragraph.addSnippet(provider.getNodeName().toUpperCase()).addStyle(AnsiStyle.BOLD);
    paragraph.addSnippet(" provider");

    resultBuilder.addNewline();//from   w w  w .ja v  a2 s  .  c  om

    paragraph = resultBuilder.addParagraph();

    paragraph.addSnippet("enabled: " + provider.isEnabled());

    paragraph = resultBuilder.addParagraph();
    paragraph.addSnippet("accounts: ");

    List<Account> accounts = provider.getAccounts();
    if (accounts == null || accounts.isEmpty()) {
        paragraph.addSnippet("[]");
    } else {
        accounts.forEach(account -> {
            AnsiParagraphBuilder list = resultBuilder.addParagraph().setIndentFirstLine(true).setIndentWidth(1);
            list.addSnippet("- ");
            list.addSnippet(account.getName());
        });
    }

    return resultBuilder.toString();
}

From source file:ai.grakn.graph.internal.computer.GraknSparkExecutor.java

public static <M> JavaPairRDD<Object, VertexWritable> prepareFinalGraphRDD(
        final JavaPairRDD<Object, VertexWritable> graphRDD,
        final JavaPairRDD<Object, ViewIncomingPayload<M>> viewIncomingRDD, final String[] elementComputeKeys) {
    // the graphRDD and the viewRDD must have the same partitioner
    assert (graphRDD.partitioner().get().equals(viewIncomingRDD.partitioner().get()));
    // attach the final computed view to the cached graph
    return graphRDD.leftOuterJoin(viewIncomingRDD).mapValues(tuple -> {
        final StarGraph.StarVertex vertex = tuple._1().get();
        vertex.dropVertexProperties(elementComputeKeys);
        final List<DetachedVertexProperty<Object>> view = tuple._2().isPresent() ? tuple._2().get().getView()
                : Collections.emptyList();
        view.forEach(property -> property.attach(Attachable.Method.create(vertex)));
        // view.clear(); // no longer needed so kill it from memory
        return tuple._1();
    });//from w  ww  .  ja  v a 2  s.  c  o m
}

From source file:dk.dma.ais.track.rest.resource.TrackResource.java

private static Set<Area> map2Areas(List<String> areaParams) {
    Set<Area> areas = Sets.newHashSet();
    if (areaParams != null && areaParams.size() > 0) {
        areaParams.forEach(area -> {
            if (area.trim().startsWith("circle")) {
                try {
                    area = URLDecoder.decode(area, "UTF-8");
                    System.out.println(area);
                    int p1 = area.indexOf("(");
                    int p2 = area.indexOf(")");
                    String[] values = area.substring(p1 + 1, p2).split(",");
                    Double lat = Double.valueOf(values[0].trim());
                    Double lon = Double.valueOf(values[1].trim());
                    Double radius = Double.valueOf(values[2].trim());
                    areas.add(new Circle(Position.create(lat, lon), radius, CoordinateSystem.CARTESIAN));
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException(e);
                }/*from  ww  w.  j av a2s .c  o  m*/
            } else {
                String[] bordersAsString = area.split("\\|");
                if (bordersAsString == null || bordersAsString.length != 4)
                    throw new IllegalArgumentException(
                            "Expected four floating point values for area argument separated by vertical bar, not: "
                                    + area);
                Double lat1 = Double.valueOf(bordersAsString[0]);
                Double lon1 = Double.valueOf(bordersAsString[1]);
                Double lat2 = Double.valueOf(bordersAsString[2]);
                Double lon2 = Double.valueOf(bordersAsString[3]);
                areas.add(BoundingBox.create(Position.create(lat1, lon1), Position.create(lat2, lon2),
                        CoordinateSystem.CARTESIAN));
            }
        });
    }
    return areas;
}

From source file:io.fabric8.vertx.maven.plugin.utils.GroovyExtensionCombiner.java

public static List<String> merge(String projectName, String projectVersion, Set<String> local,
        List<Set<String>> deps) {
    List<String> extensionClassesList = new ArrayList<>();
    List<String> staticExtensionClassesList = new ArrayList<>();

    List<Properties> all = new ArrayList<>();
    all.add(asProperties(local));/* w ww.  ja  v  a  2  s.  co m*/
    if (deps != null) {
        deps.forEach(s -> all.add(asProperties(s)));
    }

    for (Properties properties : all) {
        String staticExtensionClasses = properties.getProperty("staticExtensionClasses", "").trim();
        String extensionClasses = properties.getProperty("extensionClasses", "").trim();
        if (extensionClasses.length() > 0) {
            append(extensionClasses, extensionClassesList);
        }
        if (staticExtensionClasses.length() > 0) {
            append(staticExtensionClasses, staticExtensionClassesList);
        }
    }

    List<String> desc = new ArrayList<>();
    desc.add("moduleName=" + projectName);
    desc.add("moduleVersion=" + projectVersion);
    if (extensionClassesList.size() > 0) {
        desc.add("extensionClasses=" + join(extensionClassesList));
    }
    if (staticExtensionClassesList.size() > 0) {
        desc.add("staticExtensionClasses=" + join(staticExtensionClassesList));
    }

    return desc;
}

From source file:io.fabric8.vertx.maven.plugin.components.impl.GroovyExtensionCombiner.java

public static List<String> merge(String projectName, String projectVersion, List<String> local,
        List<List<String>> deps) {
    List<String> extensionClassesList = new ArrayList<>();
    List<String> staticExtensionClassesList = new ArrayList<>();

    List<Properties> all = new ArrayList<>();
    all.add(asProperties(local));//from   w  ww .  j  a v a  2  s. c  o  m
    if (deps != null) {
        deps.forEach(s -> all.add(asProperties(s)));
    }

    for (Properties properties : all) {
        String staticExtensionClasses = properties.getProperty("staticExtensionClasses", "").trim();
        String extensionClasses = properties.getProperty("extensionClasses", "").trim();
        if (extensionClasses.length() > 0) {
            append(extensionClasses, extensionClassesList);
        }
        if (staticExtensionClasses.length() > 0) {
            append(staticExtensionClasses, staticExtensionClassesList);
        }
    }

    List<String> desc = new ArrayList<>();
    desc.add("moduleName=" + projectName);
    desc.add("moduleVersion=" + projectVersion);
    if (extensionClassesList.size() > 0) {
        desc.add("extensionClasses=" + join(extensionClassesList));
    }
    if (staticExtensionClassesList.size() > 0) {
        desc.add("staticExtensionClasses=" + join(staticExtensionClassesList));
    }

    return desc;
}

From source file:cz.lbenda.common.ClassLoaderHelper.java

@SuppressWarnings("unchecked")
public static List<String> instancesOfClass(Class clazz, List<String> libs, boolean abstractClass,
        boolean interf) {
    List<String> classNames = new ArrayList<>();
    ClassLoader clr = createClassLoader(libs, false);
    List<String> result = new ArrayList<>();
    libs.forEach(lib -> {
        try (ZipFile file = new ZipFile(lib)) {
            file.stream().forEach(entry -> {
                if (entry.getName().equals("META-INF/services/" + clazz.getName())) {
                    try {
                        String string = IOUtils.toString(file.getInputStream(entry));
                        String[] lines = string.split("\n");
                        for (String line : lines) {
                            result.add(line.trim());
                        }/*from  ww w.  ja  v  a  2  s.  co  m*/
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                } else if (entry.getName().endsWith(".class")) {
                    String className = entry.getName().substring(0, entry.getName().length() - 6).replace("/",
                            ".");
                    classNames.add(className);
                }
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });

    classNames.forEach(cc -> {
        try {
            Class cla = clr.loadClass(cc);
            if ((interf || !cla.isInterface()) && (abstractClass || !Modifier.isAbstract(cla.getModifiers()))
                    && clazz.isAssignableFrom(cla)) {
                if (!result.contains(cc)) {
                    result.add(cc);
                }
            }
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
            /* It's common to try to create class which haven't class which need*/ }
    });
    return result;
}

From source file:edu.usu.sdl.openstorefront.web.rest.model.UserProfileView.java

public static List<UserProfileView> toViewList(List<UserProfile> profiles) {
    Map<String, Date> loginMap = ServiceProxy.getProxy().getUserService().getLastLogin(profiles);
    List<UserProfileView> views = new ArrayList<>();
    profiles.forEach(profile -> {
        views.add(UserProfileView.toView(profile, loginMap));
    });//from  w  w w. ja v  a2  s.c  om

    return views;
}

From source file:com.spankingrpgs.util.LoadStateUtils.java

/**
 * Loads all the skills into the game state.
 *//*  w  w w. j a  v  a2s  .  com*/
public static void loadSkills() {
    GameState cleanState = GameState.getCleanInstance();
    List<Skill> skills = Arrays.asList(new ScarletSlap(), new ScarletFlare(), new ScarletEyes(),
            new ScarletCord(), new ScarletBoots(), new ScarletBeam(), new ScarletArmor(), new Buzzsaw(),
            new Chainwhip(), new SoaringLeap());
    skills.forEach(skill -> cleanState.addSkill(skill.getName(), skill));
}