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.msinm.legacy.nm.LegacyNmImportRestService.java

/**
 * Imports a list of NtM templates and returns the messages actually imported
 * @param templates the NtM templates//from w w  w.  ja va 2 s . c om
 * @param weekStartDate the start date of the week
 * @param txt a log of the import
 * @return the messages actually imported
 */
private List<Message> importMessages(List<Message> templates, Date weekStartDate, StringBuilder txt) {

    List<Message> result = new ArrayList<>();

    templates.forEach(template -> {
        Message message = legacyNmImportService.importMessage(template, weekStartDate, txt);
        if (message != null) {
            result.add(message);
        }
    });

    return result;
}

From source file:com.github.frapontillo.pulse.crowd.lemmatize.morphit.MorphITLemmatizer.java

/**
 * Build the MorphIT dictionary as &lt;key:(word), value:(morphit-tag,lemma)&gt;.
 * Values are read from the resource file "morphit".
 *
 * @return A {@link HashMap} where the key is a MorphIT tag {@link String} and values are {@link
 * List} of {@link String} arrays where each element of the list represent a different
 * lemmatization form for the key; the array specifies the POS tag in the first position and the
 * lemma in the second one./*  w ww . ja  v a2 s .c om*/
 */
public HashMap<String, List<String[]>> getMorphITDictionary() {
    if (morphITDictionary == null) {
        InputStream dictStream = MorphITLemmatizer.class.getClassLoader().getResourceAsStream("morphit");
        morphITDictionary = new HashMap<>();
        try {
            List<String> mapLines = IOUtils.readLines(dictStream, Charset.forName("UTF-8"));
            mapLines.forEach(s -> {
                // for each line, split using spaces
                String[] values = spacePattern.split(s);
                if (values.length == 3) {
                    // the key is made of first and third token
                    // the value is the second token
                    List<String[]> candidates = morphITDictionary.get(values[0]);
                    if (candidates == null) {
                        candidates = new ArrayList<>();
                    }
                    candidates.add(new String[] { values[2], values[1] });
                    morphITDictionary.put(values[0], candidates);
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return morphITDictionary;
}

From source file:de.ks.text.AsciiDocParser.java

private void appendCssFile(StringBuilder builder, String cssFile) {
    URL asciiDoctorCss = getClass().getResource("/org/asciidoctor/" + cssFile);
    File file = new File(asciiDoctorCss.getFile());
    try {/*from w w w .  java2  s .c o  m*/
        List<String> lines = Files.readLines(file, Charsets.US_ASCII);
        lines.forEach(line -> builder.append(line).append("\n"));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.zdsiyan.maven.plugin.smartconfig.internal.PropertyConfigurator.java

@Override
public ByteArrayOutputStream execute(InputStream in, Charset charset, List<PointHandle> pointhandles)
        throws IOException {
    try {/*from   ww  w . j  a va  2  s. com*/
        PropertiesConfiguration configuration = new PropertiesConfiguration();
        configuration.load(in, charset.name());

        pointhandles.forEach(point -> {
            switch (point.getMode()) {
            case insert:
                configuration.addProperty(point.getExpression(), point.getValue());
                break;
            case delete:
                configuration.setProperty(point.getExpression(), "");
                break;
            case replace:
            default:
                configuration.setProperty(point.getExpression(), point.getValue());
                break;
            }
        });

        // output
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        configuration.save(out, charset.name());
        return out;
    } catch (ConfigurationException ex) {
        // FIXME
        throw new RuntimeException(ex);
    }
}

From source file:com.nike.cerberus.vault.VaultAdminClientFactory.java

/**
 * Creates clients for each Vault instance in the AutoScaling group.
 *
 * @return List of Vault clients//from w w w  .  j a v  a  2 s . c o m
 */
public List<VaultAdminClient> getClientsForCluster() {
    final List<VaultAdminClient> clients = Lists.newLinkedList();
    String vaultRootToken = configStore.getVaultRootToken();

    final VaultOutputs vaultOutputs = configStore.getVaultStackOutputs();
    final List<String> instanceDnsNames = autoScalingService
            .getPublicDnsForAutoScalingGroup(vaultOutputs.getAutoscalingGroupLogicalId());
    instanceDnsNames.forEach(instanceDnsName -> {
        if (StringUtils.isNotBlank(instanceDnsName)) {
            clients.add(getClient(vaultRootToken, instanceDnsName));
        }
    });
    return clients;
}

From source file:ch.admin.suis.msghandler.signer.SignerTest.java

public void testSigningWithOneOutbox() throws SignerException, IOException, ConfigurationException {
    initialize();//from   w  w  w  .  j a v a 2 s  .  c  o  m
    System.out.println("testSigningWithOneOutbox");
    SigningOutbox signOutbox = new SigningOutboxMHCfg(p12File, "12345678", signingOutbox1, signatureProperties,
            null);
    final File workingDir = createWorkingDir();
    final File corruptedDir = new File(workingDir, ClientCommons.CORRUPTED_DIR);
    Signer signer = new Signer(signOutbox, workingDir, corruptedDir);

    List<File> signedFiles = signer.sign();
    signedFiles.forEach((f) -> {
        f.deleteOnExit();
    });

    assertEquals(signOutbox.getAllPDFsToSign().size(), signedFiles.size());
    assertEquals(signedFiles, signOutbox.getAllPDFsToSign());
    signer.cleanUp(signedFiles);
    assertEquals(0, signOutbox.getAllPDFsToSign().size());

    // The corrupted directory must be empty
    assert FileUtils.listFiles(corruptedDir, TrueFileFilter.INSTANCE, null).isEmpty();
}

From source file:bjerne.gallery.service.impl.VideoBatchConversionJob.java

public void runBatchJob() {
    synchronized (this) {
        if (running) {
            LOG.debug("Batch job already running. Exiting");
            return;
        }//from w  w  w  .j a  va 2s . c o  m
        running = true;
    }
    LOG.debug("Starting batch job for video conversion");
    long totalStartTime = System.currentTimeMillis();
    try {
        galleryAuthorizationService.loginAdminUser();
        List<GalleryFile> allVideos = galleryService.getAllVideos();
        LOG.debug("Found {} videos for conversion", allVideos.size());
        allVideos.forEach(v -> LOG.debug("one video: {}", v.getPublicPath()));
        Collection<String> videoConversionModes = galleryService.getAvailableVideoModes();
        LOG.debug("Found the following video conversion modes: {}", videoConversionModes);
        for (GalleryFile oneGalleryFile : allVideos) {
            for (String oneConversionMode : videoConversionModes) {
                if (abort) {
                    LOG.warn("Abort requested. Skipping remainder of conversions.");
                    return;
                }
                try {
                    // We just call getVideo, as we know this will trigger a
                    // conversion if the converted file does not already
                    // exist.
                    galleryService.getVideo(oneGalleryFile.getPublicPath(), oneConversionMode);
                } catch (IOException | NotAllowedException e) {
                    LOG.error("Error while converting {} for format {}. Continuing with next video.",
                            oneGalleryFile.getPublicPath(), oneConversionMode);
                }
            }
        }
        long totalDuration = System.currentTimeMillis() - totalStartTime;
        LOG.debug("Total duration of conversion batch job: {}", totalDuration);
    } catch (Exception e) {
        LOG.error("Error while running batch job", e);
    } finally {
        galleryAuthorizationService.logoutAdminUser();
        running = false;
    }
}

From source file:com.epam.dlab.backendapi.dao.BillingDAO.java

protected Map<String, BillingDAO.ShapeInfo> getShapes(List<String> shapeNames) {
    FindIterable<Document> userInstances = getUserInstances();
    final Map<String, BillingDAO.ShapeInfo> shapes = new HashMap<>();

    for (Document d : userInstances) {
        getExploratoryShape(shapeNames, d)
                .ifPresent(shapeInfo -> shapes.put(d.getString(EXPLORATORY_ID), shapeInfo));
        @SuppressWarnings("unchecked")
        List<Document> comp = (List<Document>) d.get(COMPUTATIONAL_RESOURCES);
        comp.forEach(computational -> getComputationalShape(shapeNames, computational)
                .ifPresent(shapeInfo -> shapes.put(computational.getString(COMPUTATIONAL_ID), shapeInfo)));
    }/*from w w  w.ja  v  a 2  s . c o m*/

    appendSsnAndEdgeNodeType(shapeNames, shapes);

    log.trace("Loaded shapes is {}", shapes);
    return shapes;
}

From source file:org.opendatakit.briefcase.model.BriefcasePreferences.java

/**
 * Removes all the values associated with the specified key list in this preference
 * node, if any./*from w ww  .j  a va  2 s  .c  o m*/
 *
 * @param keys
 *          keys whose mappings are to be removed from the preference node.
 */
public void removeAll(List<String> keys) {
    keys.forEach(this::remove);
}

From source file:ch.admin.suis.msghandler.signer.SignerTest.java

/**
 * Test of sign method, of class Signer.
 *///  w w  w. j  ava2  s  . c  o  m
public void testSigningWithOneOutboxAndAProcessedDirectory()
        throws SignerException, IOException, ConfigurationException {
    initialize();
    System.out.println("testSigningWithOneOutboxAndAProcessedDirectory");
    SigningOutbox signOutbox = new SigningOutboxMHCfg(p12File, "12345678", signingOutbox1, signatureProperties,
            signingOutbox1Processed);
    final File workingDir = createWorkingDir();
    final File corruptedDir = new File(workingDir, ClientCommons.CORRUPTED_DIR);
    Signer signer = new Signer(signOutbox, workingDir, corruptedDir);

    int numberOfFiles = signOutbox.getAllPDFsToSign().size();

    List<File> signedFiles = signer.sign();
    signedFiles.forEach((f) -> {
        f.deleteOnExit();
    });
    assertEquals(numberOfFiles, signedFiles.size());

    signer.cleanUp(signedFiles);
    assertEquals(0, signOutbox.getAllPDFsToSign().size()); //now they should be moved

    assertEquals(numberOfFiles, getAllFilesFromDir(signOutbox.getProcessedDir()).size());
    // The corrupted directory must be empty
    assert FileUtils.listFiles(corruptedDir, TrueFileFilter.INSTANCE, null).isEmpty();
}