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:com.okta.swagger.codegen.AbstractOktaJavaClientCodegen.java

private void addOptionalExtension(CodegenOperation co, List<CodegenParameter> params) {

    if (params.parallelStream().anyMatch(param -> !param.required)) {
        co.vendorExtensions.put("hasOptional", true);

        List<CodegenParameter> nonOptionalParams = params.stream().filter(param -> param.required)
                .map(CodegenParameter::copy).collect(Collectors.toList());

        if (!nonOptionalParams.isEmpty()) {
            CodegenParameter param = nonOptionalParams.get(nonOptionalParams.size() - 1);
            param.hasMore = false;/*from  w  w w  .  j  av a2 s.  c om*/
            co.vendorExtensions.put("nonOptionalParams", nonOptionalParams);
        }

        // remove the noOptionalParams if we have trimmed down the list.
        if (co.vendorExtensions.get("nonOptionalParams") != null && nonOptionalParams.isEmpty()) {
            co.vendorExtensions.remove("nonOptionalParams");
        }

        // remove th body parameter if it was optional
        if (co.bodyParam != null && !co.bodyParam.required) {
            co.vendorExtensions.put("optionalBody", true);
        }
    }
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionCollectionList.java

/**
 * test remove action/*from   w w w  .  j  a  v a2s.  c om*/
 */
@Test
public final void remove() {
    final Random l_random = new Random();

    final List<?> l_elements = IntStream.range(0, l_random.nextInt(100) + 1).map(i -> l_random.nextInt())
            .boxed().collect(Collectors.toList());
    final List<?> l_list = new ArrayList<>(l_elements);
    final List<Integer> l_index = new ArrayList<>(IntStream.range(0, l_list.size() / 3)
            .map(i -> l_random.nextInt(l_list.size())).boxed().collect(Collectors.toSet()));

    final int l_startsize = l_list.size();
    final List<ITerm> l_return = new ArrayList<>();

    new CRemove().execute(false, IContext.EMPTYPLAN,
            Stream.concat(Stream.of(l_list), l_index.stream()).map(CRawTerm::from).collect(Collectors.toList()),
            l_return);

    Assert.assertEquals(l_startsize, l_list.size() + l_index.size());
    Assert.assertTrue(l_index.parallelStream().map(l_elements::get)
            .allMatch(i -> l_return.parallelStream().map(ITerm::<Number>raw).anyMatch(j -> j.equals(i))));
}

From source file:fastcall.FastCallSNP.java

private ConcurrentHashMap<String, List<List<String>>> getBamPileupResultMap(int currentChr, int binStart,
        int binEnd, HashMap<String, BufferedReader> bamPathPileupReaderMap,
        ConcurrentHashMap<BufferedReader, List<String>> readerRemainderMap) {
    ArrayList<String> empty = new ArrayList();
    ConcurrentHashMap<String, List<List<String>>> bamPileupMap = new ConcurrentHashMap(2048);
    List<String> bamList = Arrays.asList(bamPaths);
    bamList.parallelStream().forEach(bamFileS -> {
        ArrayList<List<String>> lineList = new ArrayList();
        BufferedReader br = bamPathPileupReaderMap.get(bamFileS);
        List<String> remainder = readerRemainderMap.get(br);
        boolean flag = false;
        if (remainder.size() == 0) {
            String temp = null;/* w ww  .jav  a  2  s .  c om*/
            try {
                temp = br.readLine();
            } catch (Exception e) {
            }
            if (temp != null) {
                List<String> split = FStringUtils.fastSplit(temp, "\t");
                int currentPos = Integer.valueOf(split.get(1));
                if (currentPos > binEnd) {
                    readerRemainderMap.put(br, split);
                } else {
                    lineList.add(split);
                    flag = true;
                }
            }
        } else {
            int currentPos = Integer.valueOf(remainder.get(1));
            if (currentPos <= binEnd) {
                lineList.add(remainder);
                flag = true;
                readerRemainderMap.put(br, empty);
            }
        }
        if (flag == true) {
            try {
                String temp;
                while ((temp = br.readLine()) != null) {
                    List<String> split = FStringUtils.fastSplit(temp, "\t");
                    int currentPos = Integer.valueOf(split.get(1));
                    if (currentPos < binEnd) {
                        lineList.add(split);
                    } else if (currentPos == binEnd) {
                        lineList.add(split);
                        readerRemainderMap.put(br, empty);
                        break;
                    } else {
                        readerRemainderMap.put(br, split);
                        break;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        bamPileupMap.put(bamFileS, lineList);
    });
    return bamPileupMap;
}

From source file:fastcall.FastCallSNP.java

private void performPileup(int currentChr, int startPos, int endPos, String referenceFileS) {
    System.out.println("Pileup is being performed on chromosome " + String.valueOf(currentChr) + " from "
            + String.valueOf(startPos) + " to " + String.valueOf(endPos));
    long timeStart = System.nanoTime();
    List<String> bamList = Arrays.asList(bamPaths);
    LongAdder counter = new LongAdder();
    bamList.parallelStream().forEach(bamFileS -> {
        String pileupFileS = this.bamPathPileupPathMap.get(bamFileS);
        StringBuilder sb = new StringBuilder();
        sb.append("samtools mpileup -A -B -q 30 -Q 10 -f ").append(referenceFileS).append(" ").append(bamFileS)
                .append(" -r ");
        sb.append(currentChr).append(":").append(startPos).append("-").append(endPos).append(" -o ")
                .append(pileupFileS);//from w w w.  j  a va2s .  c o m
        String command = sb.toString();
        try {
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec(command);
            p.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
        counter.increment();
        int cnt = counter.intValue();
        if (cnt % 10 == 0)
            System.out.println("Pileuped " + String.valueOf(cnt) + " bam files. Total: "
                    + String.valueOf(this.bamPaths.length));
    });
    System.out.println("Pileup is finished. Time took " + Benchmark.getTimeSpanMinutes(timeStart) + " mins");
}

From source file:delfos.rs.trustbased.WeightedGraph.java

/**
 * Devuelve la intensidad de la conexin directa entre dos nodos.
 *
 * @param node1/*from  w  ww .  j av  a  2s.  c  o  m*/
 * @param node2
 * @return
 */
private Optional<DirectedEdge> getEdge(Node node1, Node node2) {
    int indexNode1 = nodesIndex.get(node1);
    int indexNode2 = nodesIndex.get(node2);

    List<DirectedEdge> edgesFromNode1 = new ArrayList<>();
    final Iterable<DirectedEdge> directedEdges = adjMatrixEdgeWeightedDigraph.adj(indexNode1);
    for (DirectedEdge a : directedEdges) {
        if (a.weight() > 0) {
            edgesFromNode1.add(a);
        }
    }

    Optional<DirectedEdge> edgeNode1ToNode2 = edgesFromNode1.parallelStream()
            .filter(edge -> ((edge.from() == indexNode1) && (edge.to() == indexNode2))).findAny();

    return edgeNode1ToNode2;
}

From source file:fastcall.FastCallSNP.java

private void calculateVCF(ConcurrentHashMap<Integer, String> posVCFMap, List<Integer> positionList,
        int currentChr, int startPos, String chrSeq, int[][] depth, String[][] base) {
    positionList.parallelStream().forEach(position -> {
        int index = position - startPos;
        byte refBase = (byte) (chrSeq.charAt(position - 1));
        int baseIndex = Arrays.binarySearch(bases, refBase);
        if (baseIndex < 0) {

        } else {//from   w w w. j ava 2s .  c  o  m
            String vcfStr = this.getVCFString(base[index], depth[index], currentChr, position, refBase);
            if (vcfStr != null) {
                posVCFMap.put(position,
                        this.getVCFString(base[index], depth[index], currentChr, position, refBase));
            }
        }
    });
}

From source file:com.github.pires.hazelcast.HazelcastDiscoveryController.java

private void runHazelcast(final List<Pod> hazelcastPods) {
    // configure Hazelcast instance
    final Config cfg = new Config();
    cfg.setInstanceName(UUID.randomUUID().toString());
    // group configuration
    final String HC_GROUP_NAME = getEnvOrDefault("HC_GROUP_NAME", "someGroup");
    final String HC_GROUP_PASSWORD = getEnvOrDefault("HC_GROUP_PASSWORD", "someSecret");
    final int HC_PORT = Integer.parseInt(getEnvOrDefault("HC_PORT", "5701"));
    cfg.setGroupConfig(new GroupConfig(HC_GROUP_NAME, HC_GROUP_PASSWORD));
    // network configuration initialization
    final NetworkConfig netCfg = new NetworkConfig();
    netCfg.setPortAutoIncrement(false);//from  w  w  w  .ja va  2 s . c  o m
    netCfg.setPort(HC_PORT);
    // multicast
    final MulticastConfig mcCfg = new MulticastConfig();
    mcCfg.setEnabled(false);
    // tcp
    final TcpIpConfig tcpCfg = new TcpIpConfig();
    hazelcastPods.parallelStream().forEach(pod -> {
        tcpCfg.addMember(pod.getCurrentState().getPodIP());
    });
    tcpCfg.setEnabled(true);
    // network join configuration
    final JoinConfig joinCfg = new JoinConfig();
    joinCfg.setMulticastConfig(mcCfg);
    joinCfg.setTcpIpConfig(tcpCfg);
    netCfg.setJoin(joinCfg);
    // ssl
    netCfg.setSSLConfig(new SSLConfig().setEnabled(false));
    // set it all
    cfg.setNetworkConfig(netCfg);
    // run
    Hazelcast.newHazelcastInstance(cfg);
}

From source file:com.hortonworks.streamline.streams.metrics.storm.topology.StormTopologyMetricsImpl.java

private long getErrorCountFromAllComponents(String topologyId, List<Map<String, ?>> spouts,
        List<Map<String, ?>> bolts, String asUser) {
    LOG.debug("[START] getErrorCountFromAllComponents - topology id: {}, asUser: {}", topologyId, asUser);
    Stopwatch stopwatch = Stopwatch.createStarted();

    try {//  ww  w  . j av  a2 s  .c o  m
        List<String> componentIds = new ArrayList<>();

        if (spouts != null) {
            for (Map<String, ?> spout : spouts) {
                componentIds.add((String) spout.get(TOPOLOGY_JSON_SPOUT_ID));
            }
        }

        if (bolts != null) {
            for (Map<String, ?> bolt : bolts) {
                componentIds.add((String) bolt.get(TOPOLOGY_JSON_BOLT_ID));
            }
        }

        // query to components in parallel
        long errorCount = ParallelStreamUtil
                .execute(() -> componentIds.parallelStream().mapToLong(componentId -> {
                    Map componentStats = getComponentInfo(topologyId, componentId, asUser);
                    List<?> componentErrors = (List<?>) componentStats.get(TOPOLOGY_JSON_COMPONENT_ERRORS);
                    if (componentErrors != null && !componentErrors.isEmpty()) {
                        return componentErrors.size();
                    } else {
                        return 0;
                    }
                }).sum(), FORK_JOIN_POOL);

        LOG.debug("[END] getErrorCountFromAllComponents - topology id: {}, elapsed: {} ms", topologyId,
                stopwatch.elapsed(TimeUnit.MILLISECONDS));

        return errorCount;
    } finally {
        stopwatch.stop();
    }
}

From source file:com.hortonworks.streamline.streams.service.MetricsResource.java

@GET
@Path("/topologies/{id}/components/all/component_stats")
@Timed//from ww  w . j  av  a  2  s .co  m
public Response getComponentStats(@PathParam("id") Long id, @QueryParam("from") Long from,
        @QueryParam("to") Long to, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER,
            Topology.NAMESPACE, id, READ);
    assertTimeRange(from, to);
    Topology topology = catalogService.getTopology(id);
    if (topology != null) {
        List<TopologyComponent> topologyComponents = new ArrayList<>();
        List<com.hortonworks.streamline.common.QueryParam> queryParams = new ArrayList<>();
        queryParams.add(new com.hortonworks.streamline.common.QueryParam("topologyId",
                String.valueOf(topology.getId())));
        queryParams.add(new com.hortonworks.streamline.common.QueryParam("versionId",
                String.valueOf(topology.getVersionId())));

        topologyComponents.addAll(catalogService.listTopologySources(queryParams));
        topologyComponents.addAll(catalogService.listTopologyProcessors(queryParams));
        topologyComponents.addAll(catalogService.listTopologySinks(queryParams));

        Map<String, TopologyTimeSeriesMetrics.TimeSeriesComponentMetric> topologyMetrics = ParallelStreamUtil
                .execute(() -> topologyComponents.parallelStream().map(c -> {
                    try {
                        String asUser = WSUtils.getUserFromSecurityContext(securityContext);
                        return Pair.of(c, metricsService.getComponentStats(topology, c, from, to, asUser));
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }).collect(toMap(m -> m.getKey().getId().toString(), m -> m.getValue())), forkJoinPool);

        return WSUtils.respondEntity(topologyMetrics, OK);
    }

    throw EntityNotFoundException.byId(id.toString());
}

From source file:com.epam.catgenome.manager.FeatureIndexManager.java

/**
 * Filer chromosomes that contain variations, specified by filter
 *
 * @param filterForm a {@code VcfFilterForm} to filter out chromosomes
 * @return a {@code List} of {@code Chromosome} that corresponds to specified filter
 * @throws IOException//from w  ww  .j  av a 2s.c om
 */
public List<Chromosome> filterChromosomes(VcfFilterForm filterForm) throws IOException {
    Assert.isTrue(filterForm.getVcfFileIds() != null && !filterForm.getVcfFileIds().isEmpty(),
            MessageHelper.getMessage(MessagesConstants.ERROR_NULL_PARAM, VCF_FILE_IDS_FIELD));
    List<VcfFile> vcfFiles = vcfFileManager.loadVcfFiles(filterForm.getVcfFileIds());

    List<Chromosome> chromosomes = referenceGenomeManager.loadChromosomes(vcfFiles.get(0).getReferenceId());
    Map<Long, Chromosome> chromosomeMap = chromosomes.parallelStream()
            .collect(Collectors.toMap(BaseEntity::getId, chromosome -> chromosome));

    List<Long> chromosomeIds = featureIndexDao.getChromosomeIdsWhereVariationsPresentFacet(vcfFiles,
            filterForm.computeQuery(FeatureType.VARIATION));

    return chromosomeIds.stream().map(chromosomeMap::get).collect(Collectors.toList());
}