Example usage for java.util.stream StreamSupport stream

List of usage examples for java.util.stream StreamSupport stream

Introduction

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

Prototype

public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) 

Source Link

Document

Creates a new sequential or parallel Stream from a Spliterator .

Usage

From source file:com.miovision.oss.awsbillingtools.parser.DetailedLineItemParser.java

@Override
public Stream<DetailedLineItem> parse(Reader reader) throws IOException {
    final CSVParser csvParser = CSV_FORMAT.parse(reader);
    try {//from  www  .j  a  v a  2 s. c  om
        final Iterator<CSVRecord> iterator = csvParser.iterator();
        final List<String> tags = readTags(iterator);

        return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)
                .map(csvRecord -> createDetailedLineItem(csvRecord, tags)).onClose(() -> {
                    try {
                        csvParser.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                });
    } catch (Exception e) {
        csvParser.close();
        throw e;
    }
}

From source file:com.wrmsr.wava.basic.BasicSet.java

private BasicSet(ImMap<Name, Basic> basics) {
    this(basics, newPersistentHashMultimap(
            getBasicInputs(StreamSupport.stream(basics.spliterator(), false).map(entry -> entry.getValue()))));
}

From source file:org.apache.metron.stellar.common.shell.specials.MagicListFunctions.java

@Override
public StellarResult execute(String command, StellarShellExecutor executor) {

    // if '%functions FOO' then show only functions that contain 'FOO'
    String startsWith = StringUtils.trimToEmpty(command.substring(MAGIC_FUNCTIONS.length()));
    Predicate<String> nameFilter = (name -> true);
    if (StringUtils.isNotBlank(startsWith)) {
        nameFilter = (name -> name.contains(startsWith));
    }// w w w  .j  av  a2s  .c  o m

    // '%functions' -> list all functions in scope
    String functions = StreamSupport
            .stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false)
            .map(info -> String.format("%s", info.getName())).filter(nameFilter).sorted()
            .collect(Collectors.joining(", "));

    return StellarResult.success(functions);
}

From source file:org.alfresco.monitoring.dao.mongo.MongoMetricsService.java

@Override
public Stream<Metrics> getMetrics(int skip, int limit) {
    DBObject query = BasicDBObjectBuilder.start().get();
    DBObject orderBy = BasicDBObjectBuilder.start("timestampMS", 1).get();
    DBCursor cur = collection.find(query).sort(orderBy).skip(skip).limit(limit);
    Stream<Metrics> stream = StreamSupport.stream(cur.spliterator(), false).onClose(() -> cur.close()) // need to close cursor;
            .map(dbo -> Metrics.fromDBObject(dbo));
    return stream;
}

From source file:ch.heigvd.gamification.api.PointScalesEndpoint.java

@Override
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<PointScaleDTO>> pointScalesGet(
        @ApiParam(value = "token that identifies the app sending the request", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken) {

    AuthenKey apiKey = authenRepository.findByAppKey(xGamificationToken);
    if (apiKey == null) {
        return new ResponseEntity("apikey not exist", HttpStatus.UNAUTHORIZED);
    }//from   ww w  .  j ava  2s  .c  o  m

    return new ResponseEntity<>(
            StreamSupport.stream(pointscaleRepository.findAllByApp(apiKey.getApp()).spliterator(), true)
                    .map(p -> toDTO(p)).collect(toList()),
            HttpStatus.OK);
}

From source file:client.DockerPackageClient.java

/**
 * Gets all of the packages in the registry.
 *
 * @return a response with all of the packages
 *///from   www  .  j  av a2 s.  c  o  m
public F.Promise<PackageListResponse> getAllPackages() {

    final F.Promise<List<String>> repoNamesPromise = WS.client().url(uri("/v1/search").toString()).get()
            .map(searchResponse -> {
                // searchResponse = { results: [ {name: "", description: "" }, ... ] }
                final Spliterator<JsonNode> resultsIter = searchResponse.asJson().get("results").spliterator();

                return StreamSupport.stream(resultsIter, false)
                        .map(jsonResult -> jsonResult.get("name").asText()).collect(Collectors.toList());

            });

    final F.Promise<List<WSResponse>> tagListJsonNodes = repoNamesPromise.flatMap(repoNames -> {

        final List<WSRequest> requests = repoNames.stream()
                .map(name -> WS.client().url(uri(String.format("/v1/repositories/%s/tags", name)).toString()))
                .collect(Collectors.toList());

        return concurrentExecute(requests, 5);

    });

    // Combine the repo names and the tag lists into a Map, and package in a PackageListResponse:
    return repoNamesPromise.zip(tagListJsonNodes).map(namesAndJsonTuple -> {

        final Map<String, List<ImageMetadata>> packages = Maps
                .newHashMapWithExpectedSize(namesAndJsonTuple._1.size());

        final Iterator<String> repoNamesIter = namesAndJsonTuple._1.iterator();
        final Iterator<WSResponse> tagListsIter = namesAndJsonTuple._2.iterator();

        while (repoNamesIter.hasNext() && tagListsIter.hasNext()) {
            final String nextName = repoNamesIter.next();
            final WSResponse tagListResponse = tagListsIter.next();
            final List<ImageMetadata> tagList = repoTagListToImages(tagListResponse, nextName);

            packages.put(nextName, tagList);
        }

        return new PackageListResponse(packages);
    });
}

From source file:com.wrmsr.wava.basic.BasicLoopInfo.java

public static Set<Name> findBasicLoops(Iterable<Basic> basics, BasicDominatorInfo di) {
    return StreamSupport.stream(basics.spliterator(), false)
            .filter(b -> di.getDominanceFrontier(b.getName()).contains(b.getName())).map(Basic::getName)
            .collect(toHashSet());/*from  www .ja  v a 2s.  c o  m*/
}

From source file:com.ikanow.aleph2.analytics.storm.assets.OutputBolt.java

/** Converts from a tuple of a linked hash map
 * @param t//from w ww  . j  a v a 2  s . c o  m
 * @return
 */
public static LinkedHashMap<String, Object> tupleToLinkedHashMap(final Tuple t) {
    return StreamSupport.stream(t.getFields().spliterator(), false)
            .collect(Collectors.toMap(f -> f, f -> t.getValueByField(f), (m1, m2) -> m1, LinkedHashMap::new));
}

From source file:org.apache.metron.stellar.common.shell.specials.DocCommand.java

@Override
public StellarResult execute(String command, StellarShellExecutor executor) {
    StellarResult result;/*  w  w w.j  a va  2  s .c om*/

    // expect ?functionName
    String functionName = StringUtils.substring(command, 1);

    // grab any docs for the given function
    Spliterator<StellarFunctionInfo> fnIterator = executor.getFunctionResolver().getFunctionInfo()
            .spliterator();
    Optional<StellarFunctionInfo> functionInfo = StreamSupport.stream(fnIterator, false)
            .filter(info -> StringUtils.equals(functionName, info.getName())).findFirst();

    if (functionInfo.isPresent()) {
        result = success(docFormat(functionInfo.get()));
    } else {
        result = error(String.format("No docs available for function '%s'", functionName));
    }

    return result;
}

From source file:com.michaelwitbrock.jacksonstream.JsonArrayStreamDataSupplier.java

public Stream<T> getStream() {
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(this, 0), false);
}