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:io.spring.initializr.web.ui.UiController.java

private static String writeDependencies(List<DependencyItem> items) {
    JSONObject json = new JSONObject();
    List<Map<String, Object>> maps = new ArrayList<>();
    items.forEach(d -> maps.add(mapDependency(d)));
    json.put("dependencies", maps);
    return json.toString();
}

From source file:com.liferay.apio.architect.internal.annotation.representor.processor.TypeProcessor.java

private static ParsedType _processType(Class<?> typeClass, boolean nested) {
    Type type = typeClass.getAnnotation(Type.class);

    Builder builder = new Builder(type, typeClass);

    if (!nested) {
        Method idMethod = Try.fromFallible(() -> getMethodsListWithAnnotation(typeClass, Id.class))
                .filter(methods -> !methods.isEmpty()).map(methods -> methods.get(0)).orElse(null);

        builder.idMethod(idMethod);/*w  ww.  j a  va2  s  .  c o m*/
    }

    List<Method> methods = getMethodsListWithAnnotation(typeClass, Field.class);

    methods.forEach(method -> _processMethod(builder, method));

    return builder.build();
}

From source file:io.ignitr.dispatchr.manager.domain.client.FindClientsResponse.java

public static FindClientsResponse from(List<Client> clients) {
    FindClientsResponse response = new FindClientsResponse();

    clients.forEach(client -> {
        Result result = new Result();
        result.setClientId(client.getClientId());
        result.setOwnerName(client.getOwnerName());
        result.setOwnerEmail(client.getOwnerEmail());

        result.add(linkTo(methodOn(ClientKeysController.class).findAll(client.getClientId(), null))
                .withRel("keys"));

        response.addResult(result);/*from w w  w  .  j  a  v a2s.  c  o m*/
    });

    return response;
}

From source file:com.github.blindpirate.gogradle.core.cache.DirectorySnapshot.java

private static String md5(File projectRoot, File targetDir) {
    List<File> allFilesInDir = IOUtils.listAllDescendents(targetDir).stream().sorted(File::compareTo)
            .collect(Collectors.toList());
    StringBuilder sb = new StringBuilder();
    allFilesInDir.forEach(file -> {
        Path relativePath = projectRoot.toPath().relativize(file.toPath());
        sb.append(file.isFile() ? "f" : "d").append(File.pathSeparatorChar).append(toUnixString(relativePath))
                .append(File.pathSeparatorChar).append(file.length()).append(File.pathSeparatorChar)
                .append(file.lastModified()).append(File.pathSeparatorChar);
    });//from   w  w  w .ja v  a2  s .c  om
    return DigestUtils.md5Hex(sb.toString());
}

From source file:com.netflix.imfutility.itunes.inputparameters.ITunesInputParametersValidator.java

private static void validateFiles(List<File> files, String fileType) throws ArgumentValidationException {
    if (files != null && !files.isEmpty()) {
        files.forEach((file) -> validateFile(file, fileType));
    }//from  ww w . j  a v  a  2 s .c  o  m
}

From source file:co.runrightfast.core.utils.JsonUtils.java

static javax.json.JsonArray toJsonArray(final List<String> stringList) {
    if (CollectionUtils.isEmpty(stringList)) {
        return EMPTY_ARRAY;
    }//from w ww . j  av  a 2 s .co m

    final JsonArrayBuilder json = Json.createArrayBuilder();
    stringList.forEach(json::add);
    return json.build();
}

From source file:edu.usu.sdl.openstorefront.core.view.ComponentMediaView.java

public static List<ComponentMediaView> toViewList(List<ComponentMedia> mediaList) {
    List<ComponentMediaView> componentMediaViews = new ArrayList<>();
    mediaList.forEach(media -> {
        componentMediaViews.add(toView(media));
    });//w w w . j a va 2  s  .c  o  m
    return componentMediaViews;
}

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

public static ClassLoader createClassLoader(List<String> libs, boolean useSystemClassPath) {
    List<URL> urls = new ArrayList<>(libs.size());
    libs.forEach(lib -> {
        try {//from  w w  w  .  j  a va  2 s  .c om
            urls.add((new File(lib)).toURI().toURL());
        } catch (MalformedURLException e) {
            throw new RuntimeException("The file wasn't readable: " + lib, e);
        }
    });

    URLClassLoader urlCl;
    if (useSystemClassPath) {
        urlCl = new URLClassLoader(urls.toArray(new URL[urls.size()]), System.class.getClassLoader());
    } else {
        urlCl = new URLClassLoader(urls.toArray(new URL[urls.size()]));
    }
    return urlCl;
}

From source file:net.bcsw.sdnwlan.IngressVlans.java

/**
 * Build up the traffic treatment and selector for a flow's vlans
 *
 * @param selector/* w ww  .j a va2  s.c  om*/
 * @param ingress
 * @param egress
 * @return
 */
public static TrafficTreatment.Builder vlanMatchAndTreatment(TrafficSelector.Builder selector,
        SDNWLANConnectPoint ingress, SDNWLANConnectPoint egress) {

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    // Always match any ingress vlans. The input VLAN list is arranged with outermost tag first

    List<VlanId> ingressVlans = ingress.getIngressVlans().getVlanList();

    ingressVlans.forEach(vid -> selector.matchVlanId(vid));

    // If egress vlans not equal to ingress, some type of action is required

    List<VlanId> egressVlans = egress.getIngressVlans().getVlanList();

    if (!egressVlans.equals(ingressVlans)) {

        // Do simple push/pop all checks cases first

        if (ingressVlans.size() == 0) {

            // Push all egress vlans

            egressVlans.forEach(vid -> treatment.pushVlan().setVlanId(vid));

        } else if (egressVlans.size() == 0) {

            // Pop all ingress vlans

            ingressVlans.forEach(vid -> treatment.popVlan());

        } else {
            // TODO: Implement this more complex case
        }
    }
    return treatment;
}

From source file:com.nebkat.plugin.youtube.YoutubeRetriever.java

private static Map<String, String> getNameValuePairMap(String queryString) {
    List<NameValuePair> infoMap = new ArrayList<>();
    URLEncodedUtils.parse(infoMap, new Scanner(queryString), "UTF-8");
    Map<String, String> map = new HashMap<>(infoMap.size());
    infoMap.forEach((pair) -> map.put(pair.getName(), pair.getValue()));
    return map;/*from   w ww .  ja v  a  2 s  . com*/
}