Example usage for java.util List parallelStream

List of usage examples for java.util List parallelStream

Introduction

In this page you can find the example usage for java.util List parallelStream.

Prototype

default Stream<E> parallelStream() 

Source Link

Document

Returns a possibly parallel Stream with this collection as its source.

Usage

From source file:ru.VirtaMarketAnalyzer.main.Wizard.java

public static void saveUnitTypeImg(final List<UnitType> unitTypes) {
    unitTypes.parallelStream().forEach(unitType -> {
        saveImg(unitType.getImgUrl());/*from  ww w .  jav  a 2s  .  co m*/
    });
}

From source file:com.firewallid.util.FIUtils.java

public static <U, V extends Number> List<Tuple2<U, Double>> sumList(List<Tuple2<U, V>> l1,
        List<Tuple2<U, V>> l2) {
    l1.addAll(l2);// www. jav a  2 s.com
    List<Tuple2<U, Double>> sum = l1.parallelStream()
            .collect(Collectors
                    .groupingBy(data -> data._1(), Collectors.mapping(data -> data._2(), Collectors.toList())))
            .entrySet().parallelStream()
            .map(data -> new Tuple2<>(data.getKey(),
                    data.getValue().parallelStream().mapToDouble(value -> value.doubleValue()).sum()))
            .collect(Collectors.toList());

    return sum;
}

From source file:com.civprod.writerstoolbox.testarea.UnsupervisedDiscourseSegmentation.java

public static List<List<String>> segment(Document<?> inDocument, SentenceDetector inSentenceDetector,
        StringTokenizer inStringTokenizer) {
    List<String> concatenateTokens = concatenateTokens(inDocument, inSentenceDetector, inStringTokenizer);
    List<String> stemmAndFilterList = TokenUtil.stemmAndFilterList(concatenateTokens);
    List<List<String>> splitIntoFixLengthLists = splitIntoFixLengthLists(stemmAndFilterList, 20);
    List<Counter<String>> counters = splitIntoFixLengthLists.parallelStream()
            .map((List<String> curSentence) -> CounterUtils.count(curSentence)).collect(Collectors.toList());
    List<Double> cosineSimilarity = new ArrayList<>(counters.size() - 20);
    for (int i = 0; i < (counters.size() - 20); i++) {
        cosineSimilarity.add(cosineSimilarityStemmedAndFiltered(Counter.join(counters.subList(i, i + 10)),
                Counter.join(counters.subList(i + 11, i + 20))));
    }//from   w ww. j  a  va2s  .  c  o m
    List<Double> valleys = new ArrayList<>(cosineSimilarity.size() - 2);
    for (int i = 0; i < valleys.size(); i++) {
        double ya1 = cosineSimilarity.get(i);
        double ya2 = cosineSimilarity.get(i + 1);
        double ya3 = cosineSimilarity.get(i + 2);
        valleys.add((ya1 - ya2) + (ya3 - ya2));
    }
    SummaryStatistics valleyStatistics = valleys.parallelStream().collect(SummaryStatisticCollector.instance);
    double cutoffThreshold = valleyStatistics.getMean() - valleyStatistics.getStandardDeviation();
    int lastLocation = 0;
    List<Span> spans = new ArrayList<>(1);
    for (int i = 0; i < valleys.size(); i++) {
        double curValley = valleys.get(i);
        if (curValley < cutoffThreshold) {
            int curLocation = (i + 11) * 20;
            spans.add(new Span(lastLocation, curLocation));
            lastLocation = curLocation;
        }
    }
    spans.add(new Span(lastLocation, concatenateTokens.size()));
    return spans.parallelStream()
            .map((Span curSpan) -> concatenateTokens.subList(curSpan.getStart(), curSpan.getEnd()))
            .collect(Collectors.toList());
}

From source file:org.apdplat.superword.tools.WordSources.java

/**
 * ?????//  w w  w.  j  a v  a 2 s  .  com
 * @param index ???0
 * @param files ??/
 * @return ??????
 */
public static Set<Word> get(int index, String... files) {
    Set<Word> set = new HashSet<>();
    for (String file : files) {
        URL url = null;
        if (file.startsWith("/")) {
            url = WordSources.class.getResource(file);
        } else {
            try {
                url = Paths.get(file).toUri().toURL();
            } catch (Exception e) {
                LOGGER.error("URL", e);
            }
        }
        if (url == null) {
            LOGGER.error("??" + file);
            continue;
        }
        System.out.println("parse word file: " + url);
        List<String> words = getExistWords(url);
        Set<Word> wordSet = words.parallelStream()
                .filter(line -> !line.trim().startsWith("#") && !"".equals(line.trim()))
                .filter(line -> line.trim().split("\\s+").length >= index + 1)
                .map(line -> new Word(line.trim().split("\\s+")[index], ""))
                .filter(word -> StringUtils.isAlphanumeric(word.getWord())).collect(Collectors.toSet());
        set.addAll(wordSet);
    }
    System.out.println("unique words count: " + set.size());
    return set;
}

From source file:com.firewallid.util.FIUtils.java

public static Vector sumVector(Vector v1, Vector v2) {
    if (v1.size() != v2.size()) {
        return null;
    }// w  ww  . j  a v a 2s  . co m

    List<Tuple2<Integer, Double>> v1List = vectorToList(v1);
    List<Tuple2<Integer, Double>> v2List = vectorToList(v2);

    List<Tuple2<Integer, Double>> sumList = combineList(v1List, v2List);

    /* Sum value of same key-pair */
    List<Tuple2<Integer, Double>> collect = sumList.parallelStream()
            .collect(Collectors.groupingBy(t -> t._1,
                    Collectors.mapping((Tuple2<Integer, Double> t) -> t._2, Collectors.toList())))
            .entrySet().parallelStream()
            .map((Map.Entry<Integer, List<Double>> t) -> new Tuple2<Integer, Double>(t.getKey(),
                    t.getValue().parallelStream().mapToDouble(Double::doubleValue).sum()))
            .collect(Collectors.toList());

    return Vectors.sparse(v1.size(), collect);
}

From source file:blog.identify.IdentifyMultipleFacesExample.java

private static java.util.List<BufferedImage> extractImagesFromPeople(People people) {
    java.util.List<BufferedImage> images = new ArrayList<>();
    java.util.List<People.SimplePerson> simplePersons = people.simplePersons();
    images.addAll(simplePersons.parallelStream()
            .map(simplePerson -> BlogHelper.loadAndNameCandidateImages(simplePerson.personImages.get(0)))
            .collect(Collectors.toList()));
    return images;
}

From source file:com.civprod.writerstoolbox.NaturalLanguage.util.RegexStringTokenizer.java

private static List<String> Tokenize(List<String> ReturnList, Pattern possivePattern,
        List<Pattern> ignorePatterns, int sizeGuess) {
    List<String> TempList = new java.util.ArrayList<>(sizeGuess);
    for (String curWord : ReturnList) {
        if (ignorePatterns.parallelStream()
                .noneMatch((Pattern curPattern) -> curPattern.matcher(curWord).matches())) {
            Matcher matcher = possivePattern.matcher(curWord);
            int lastEnd = 0;
            while (matcher.find()) {
                String pre = curWord.substring(lastEnd, matcher.start());
                if (!pre.isEmpty()) {
                    TempList.add(pre);/*  w  w w.j  a v a2 s . c om*/
                }
                String match = curWord.substring(matcher.start(), matcher.end());
                if (!match.isEmpty()) {
                    TempList.add(match);
                }
                lastEnd = matcher.end();
            }
            String end = curWord.substring(lastEnd);
            if (!end.isEmpty()) {
                TempList.add(end);
            }
        } else {
            TempList.add(curWord);
        }
    }
    return TempList;
}

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<Map<Integer, Double>> appendFeatures(List<Map<Integer, Double>> list1,
        List<Map<Integer, Double>> list2) {
    if (list1.isEmpty()) {
        return list2;
    } else if (list2.isEmpty()) {
        return list1;
    }/*from   ww w  .j  av a 2s.  c  om*/
    int max = list1.parallelStream().map(Map::keySet).flatMap(Set::parallelStream).mapToInt(i -> i).max()
            .getAsInt();
    return range(0, list1.size()).boxed().map(i -> sum(list1.get(i), addToKeys(list2.get(i), max)))
            .collect(toList());
}

From source file:com.kantenkugel.discordbot.moduleutils.DocParser.java

public static String get(String name) {
    String[] split = name.toLowerCase().split("[#\\.]", 2);
    if (split.length != 2)
        return "Incorrect Method declaration";
    List<Documentation> methods;
    synchronized (docs) {
        if (!docs.containsKey(split[0]))
            return "Class not Found!";
        methods = docs.get(split[0]);//  w ww. j  a v a  2  s  . c  o m
    }
    methods = methods.parallelStream().filter(doc -> doc.matches(split[1]))
            .sorted(Comparator.comparingInt(doc -> doc.argTypes.size())).collect(Collectors.toList());
    if (methods.size() == 0)
        return "Method not found/documented in Class!";
    if (methods.size() > 1 && methods.get(0).argTypes.size() != 0)
        return "Multiple methods found: " + methods.parallelStream()
                .map(m -> '(' + StringUtils.join(m.argTypes, ", ") + ')').collect(Collectors.joining(", "));
    Documentation doc = methods.get(0);
    StringBuilder b = new StringBuilder();
    b.append("```\n").append(doc.functionHead).append("\n```\n").append(doc.desc);
    if (doc.args.size() > 0) {
        b.append('\n').append('\n').append("**Arguments:**");
        doc.args.entrySet().stream().map(e -> "**" + e.getKey() + "** - " + e.getValue())
                .forEach(a -> b.append('\n').append(a));
    }
    if (doc.returns != null)
        b.append('\n').append('\n').append("**Returns:**\n").append(doc.returns);
    if (doc.throwing.size() > 0) {
        b.append('\n').append('\n').append("**Throws:**");
        doc.throwing.entrySet().stream().map(e -> "**" + e.getKey() + "** - " + e.getValue())
                .forEach(a -> b.append('\n').append(a));
    }
    return b.toString();
}

From source file:com.github.aptd.simulation.datamodel.CXMLReader.java

/**
 * filter an object list/*w  w  w .ja  v  a  2s .  co  m*/
 *
 * @param p_list object list
 * @return agent-reference exist
 */
private static boolean hasagentname(final List<Object> p_list) {
    return p_list.parallelStream().anyMatch(a -> a instanceof AgentRef);
}