Example usage for java.util ArrayList forEach

List of usage examples for java.util ArrayList forEach

Introduction

In this page you can find the example usage for java.util ArrayList forEach.

Prototype

@Override
public void forEach(Consumer<? super E> action) 

Source Link

Usage

From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java

public static void main(String[] args) throws Exception {
    TreeSet<UDate> d = Database.getIntradayDates();
    ArrayList<TreeSet<UDate>> m = timesegments(d, 1000 * 60 * 60 * 24 * 5);
    m.forEach((x) -> {
        LOG.debug(x.size() + "\t" + x);
    });// w  ww . j a  v  a 2 s .  c  o m
    Set l = longestSet(m);
    LOG.debug(l.size() + "\t" + l);

    //      testCookies();
    //LOG.debug(Database.getGoogleQuotes("BIT:ENEL"));
    /*java.util.HashMap<String,TreeSet<UDate>> map=new HashMap<String, TreeSet<UDate>>();
    map=Database.intradayDates();
    for (String h : map.keySet()){
    TreeSet<UDate> ts= map.get(h);
    ts.forEach((d)->{LOG.debug(h+"\t"+d);});
            
    }*/

    if (true)
        return;
    //fetchEuroNext();
    //Fints f=Database.getFintsQuotes(Optional.of("XMIB"),Optional.of("MLSE") , Optional.empty());
    //f.getSerieCopy(3).plot("xmib", "price");
    //LOG.debug(Database.getGoogleQuotes("BIT:ENEL"));
    // LOG.debug(com.ettoremastrogiacomo.utils.Encoding.base64encode(com.ettoremastrogiacomo.utils.Encoding.getSHA1("prova".getBytes())));;

}

From source file:Main.java

/**
 * Converts a file to a string// w  ww . ja v  a  2s  .c  om
 * @param f The file
 * @return The string
 * @throws IOException Thrown in any IOException occurs
 */
public static String fileToString(File f) throws IOException {
    ArrayList<String> list = new ArrayList<>(Files.readAllLines(f.toPath()));
    StringBuilder builder = new StringBuilder();
    list.forEach(builder::append);
    return builder.toString();
}

From source file:it.serasoft.pdi.PDITools.java

private static void startReadingDir(String srcDir, boolean recurse, boolean followLinks) {

    File f = new File(srcDir);

    if (!f.isDirectory())
        // TODO Manage directory is not a directory
        System.exit(-3);/*from w  w  w  .  j av  a2  s .c om*/

    ArrayList<File> completeFilesList = new ArrayList<>();
    getFilesList(f, completeFilesList, recurse);

    if (!completeFilesList.isEmpty()) {
        completeFilesList.forEach(file -> startAnalysis(file, followLinks));
    }
}

From source file:org.zanata.arquillian.Deployments.java

private static void printArchiveContents(Archive<?> archive) {
    // We could just use archive.toString(verbose=true), but it's
    // nicer to have sorting.
    @SuppressWarnings("unchecked")
    ArrayList<ArchivePath> paths = new ArrayList<>(archive.getContent().keySet());
    Collections.sort(paths);//from w w w . j  a  va 2 s  . c om
    log.info("Deployment contents:");
    paths.forEach(it -> log.info("  " + it.get()));
}

From source file:org.darsana.nlp.Scorer.java

public static Map<String, Double> ScoreGram(String srcCorp, String dstCorp, int method, int gramSize) {
    // Generate grams from corpora, store in Maps
    Map<String, Double> conceptMap = generateCommonConceptMap(srcCorp, dstCorp, gramSize);

    if (method == Type.RAW_FREQUENCY.getValue()) {
        ArrayList<String> toRemove = new ArrayList<>();
        // Return raw frequency after nixing any terms that occur only once.
        conceptMap.keySet().stream().filter((key) -> (conceptMap.get(key) == 1)).forEachOrdered((key) -> {
            toRemove.add(key);//  www . j  av  a2 s. c o  m
        });

        toRemove.forEach((key) -> {
            conceptMap.remove(key);
        });

        return conceptMap;
    } else if (method == Type.RELATIVE_FREQUENCY.getValue()) {
        // Return harmonic frequency of terms as they occur across all documents.
        Map<String, Double> termFrequencyMap = generateCommonConceptMap(srcCorp, dstCorp, 1);
        Map<String, Double> relativeFrequencyMap = new TreeMap<>();

        conceptMap.keySet().forEach((key) -> {
            double freq = harmonicFrequency(key, termFrequencyMap);

            if (freq > 1.0) {
                relativeFrequencyMap.put(key, freq);
            }
        });

        return relativeFrequencyMap;
    } else {
        // Return most similar strings across all documents, likely needs trigrams or larger 
        // to be truly useful.
        Map<String, Double> srcMap = generateConceptMap(srcCorp, gramSize);
        Map<String, Double> dstMap = generateConceptMap(dstCorp, gramSize);
        Map<String, Double> distanceMap = new TreeMap<>();

        Object[] srcKeys = srcMap.keySet().toArray();
        Object[] dstKeys = dstMap.keySet().toArray();

        for (int i = 0; i < srcKeys.length - 1; i++) {
            for (int j = 0; j < dstKeys.length - 1; j++) {
                double score = StringUtils.getJaroWinklerDistance(srcKeys[i].toString(), dstKeys[j].toString());

                if (score >= 0.9) {
                    distanceMap.put(srcKeys[i] + "," + dstKeys[j], score);
                }
            }
        }

        return distanceMap;
    }
}

From source file:org.benetech.secureapp.generator.ObtainXFormController.java

@ModelAttribute("formsImpMap")
public static OrderedMap<String, String> populateFormsMap() throws MalformedURLException, IOException {
    OrderedMap<String, String> formsImpMap = new OrderedMap<String, String>();
    String chooseAnXForm = new String(SecureAppGeneratorApplication.getMessage("combo.select_default_form"));
    formsImpMap.put(chooseAnXForm, null);
    File xFormsDirectory = new File(XFORMS_DEFAULT_DIRECTORY);
    if (!xFormsDirectory.exists())
        return formsImpMap;
    ArrayList<File> files = new ArrayList<File>(Arrays.asList(xFormsDirectory.listFiles()));
    files.forEach((file) -> addForms(formsImpMap, file));
    return formsImpMap;
}

From source file:org.darsana.nlp.Scorer.java

private static Map<String, Double> generateCommonConceptMap(String srcCorp, String dstCorp, int gramSize) {
    NGram srcGrams = new NGram(gramSize, srcCorp);
    NGram dstGrams = new NGram(gramSize, dstCorp);

    Map<String, Double> conceptMap, srcMap, dstMap;
    conceptMap = new TreeMap<>();
    srcMap = generateConceptMap(srcCorp, gramSize);
    dstMap = generateConceptMap(dstCorp, gramSize);

    conceptMap.putAll(srcMap);// ww w.  j av a 2s  .  co  m
    conceptMap.putAll(dstMap);

    ArrayList<String> toRemove = new ArrayList();

    // Remove all concepts that occur in one text and not the other
    conceptMap.keySet().stream().filter((key) -> (!srcMap.containsKey(key) || !dstMap.containsKey(key)))
            .forEachOrdered((key) -> {
                toRemove.add(key);
            });

    toRemove.forEach((rem) -> {
        conceptMap.remove(rem);
    });

    return conceptMap;
}

From source file:com.sonicle.webtop.mail.bol.model.ImapQuery.java

public static SearchTerm toSearchTerm(String allFlagStrings[], List<Tag> atags, QueryObj query,
        DateTimeZone timezone) {/*from  ww  w.  j  a  v  a  2 s .  c o m*/
    SearchTerm searchTerm = null;
    ArrayList<SearchTerm> terms = new ArrayList<SearchTerm>();

    if (query != null) {
        ArrayList<Condition> conditionsList = query.conditions;
        String allText = query.allText;

        if (allText != null && allText.trim().length() > 0) {
            SearchTerm defaultterms[] = toDefaultSearchTerm(allText);
            terms.add(new OrTerm(defaultterms));
        }

        conditionsList.forEach(condition -> {
            String key = condition.keyword;
            String value = condition.value;

            if (key.equals(FROM)) {
                terms.add(new FromStringTerm(value));
            } else if (key.equals(TO)) {
                terms.add(new RecipientStringTerm(Message.RecipientType.TO, value));
            } else if (key.equals(SUBJECT)) {
                terms.add(new SubjectTerm(value));
            } else if (key.equals(MESSAGE)) {
                terms.add(new BodyTerm(value));
            } else if (key.equals(EVERYWHERE)) {
                SearchTerm anyterms[] = toAnySearchTerm(value);
                terms.add(new OrTerm(anyterms));
            } else if (key.equals(AFTER)) {
                Date afterDate = ImapQuery.parseDate(value, timezone);
                terms.add(new ReceivedDateTerm(DateTerm.GE, afterDate));
                terms.add(new SentDateTerm(DateTerm.GE, afterDate));
            } else if (key.equals(BEFORE)) {
                Date beforeDate = ImapQuery.parseDate(value, timezone);
                terms.add(new ReceivedDateTerm(DateTerm.LE, beforeDate));
                terms.add(new SentDateTerm(DateTerm.LE, beforeDate));

            } else if (value.equals(ATTACHMENT)) {

            } else if (value.equals(UNREAD)) {
                terms.add(new FlagTerm(new Flags(Flag.SEEN), false));
            } else if (value.equals(FLAGGED)) {
                FlagTerm fts[] = new FlagTerm[allFlagStrings.length + 1];
                fts[0] = new FlagTerm(new Flags(Flag.FLAGGED), true);
                for (int i = 0; i < allFlagStrings.length; ++i)
                    fts[i + 1] = new FlagTerm(new Flags(allFlagStrings[i]), true);
                terms.add(new OrTerm(fts));
            } else if (value.equals(TAGGED)) {
                FlagTerm fts[] = new FlagTerm[atags.size()];
                int i = 0;
                for (Tag tag : atags)
                    fts[i++] = new FlagTerm(new Flags(tag.getTagId()), true);
                terms.add(new OrTerm(fts));
            } else if (value.equals(UNANSWERED)) {
                terms.add(new FlagTerm(new Flags(Flag.ANSWERED), false));
            } else if (value.equals(PRIORITY)) {
                HeaderTerm p1 = new HeaderTerm("X-Priority", "1");
                HeaderTerm p2 = new HeaderTerm("X-Priority", "2");
                terms.add(new OrTerm(p1, p2));
            }

        });
    }

    int n = terms.size();
    if (n == 1) {
        searchTerm = terms.get(0);
    } else if (n > 1) {
        SearchTerm vterms[] = new SearchTerm[n];
        terms.toArray(vterms);
        searchTerm = new AndTerm(vterms);
    }
    return searchTerm;
}

From source file:no.ntnu.okse.web.controller.StatsController.java

/**
 * Returnes all the information needed to refresh the stats-pane
 *
 * @return A HashMap containing all the information
 *///from w  w  w  .j  a  va 2  s.c o  m
@RequestMapping(method = RequestMethod.GET, value = GET_STATS)
public @ResponseBody HashMap<String, Object> getAllStats() {
    CoreService cs = CoreService.getInstance();
    SubscriptionService ss = SubscriptionService.getInstance();
    TopicService ts = TopicService.getInstance();

    HashMap<String, Object> result = new HashMap<>();

    // CoreService statistics
    result.put("coreServiceStatistics", new HashMap<String, Object>() {
        {
            put("totalMessagesSent", cs.getTotalMessagesSentFromProtocolServers());
            put("totalMessagesReceived", cs.getTotalMessagesReceivedFromProtocolServers());
            put("totalRequests", cs.getTotalRequestsFromProtocolServers());
            put("totalBadRequests", cs.getTotalBadRequestsFromProtocolServers());
            put("totalErrors", cs.getTotalErrorsFromProtocolServers());
            put("publishers", ss.getNumberOfPublishers());
            put("subscribers", ss.getNumberOfSubscribers());
            put("topics", ts.getTotalNumberOfTopics());
        }
    });

    // ProtocolServer statistics
    ArrayList<ProtocolServer> protocols = cs.getAllProtocolServers();
    ArrayList<ProtocolStats> protocolStats = new ArrayList<>();

    protocols.forEach(p -> {
        protocolStats.add(new ProtocolStats(p.getProtocolServerType(), p.getTotalMessagesSent(),
                p.getTotalMessagesReceived(), p.getTotalRequests(), p.getTotalBadRequests(),
                p.getTotalErrors()));
    });
    result.put("protocolServerStatistics", protocolStats);

    return result;
}

From source file:VcfController.java

public void output(ArrayList<VariantContext> variants) {
    vcfwriter.writeHeader(header);
    variants.forEach(variant -> vcfwriter.add(variant));
}