Example usage for java.util.stream IntStream parallel

List of usage examples for java.util.stream IntStream parallel

Introduction

In this page you can find the example usage for java.util.stream IntStream parallel.

Prototype

@Override
    IntStream parallel();

Source Link

Usage

From source file:io.pivotal.demo.smartgrid.frontend.timeseries.AggregateCounterTimeSeriesRepository.java

@Override
public Map<String, TimeSeriesCollection> getTimeSeriesData(TimeSeriesDataRequest dataRequest) {

    int houseId = dataRequest.getHouseId();

    IntStream houseNumStream = houseId == GRID_HOUSE_ID ? IntStream.rangeClosed(HOUSE_ID_MIN, HOUSE_ID_MAX)
            : IntStream.of(houseId);

    List<AggregateCounterCollection> aggregateCounterCollections = houseNumStream.parallel()
            .mapToObj(i -> new TimeSeriesDataRequest(dataRequest, i)).map(this::fetchAggregateCounterData)
            .filter(acc -> acc != null && !acc.getAggregateCounters().isEmpty()).collect(Collectors.toList());

    Map<String, TimeSeriesCollection> result = new HashMap<>();
    for (AggregateCounterCollection acc : aggregateCounterCollections) {

        TimeSeriesCollection tsc = convertToTimeSeriesCollection(acc);
        result.put(tsc.getName(), tsc);// w ww.  java2 s. c o  m
    }

    TimeSeriesCollection totalGridTimeSeriesCollection = aggreagteGridTotalTimeSeries(result);

    result.put("h_-1", totalGridTimeSeriesCollection);

    return result;
}

From source file:org.protelis.test.TestLanguage.java

private static void testFileWithMultipleRuns(final String file, final IntStream stream) {
    stream.parallel().forEach(i -> {
        testFile(file, i);/*  w ww . j ava2  s.  c  o  m*/
    });
}