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.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java

@Override
public List<PageExperiment> getExperimentsWithoutLabels(Application.Name applicationName, Page.Name pageName) {
    Stream<PageExperimentByAppNamePage> resultList = Stream.empty();
    try {/*from ww w.ja v  a2  s  .  co  m*/
        Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor
                .selectBy(applicationName.toString(), pageName.toString());
        resultList = StreamSupport
                .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false);
    } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) {
        throw new RepositoryException("Could not retrieve the experiments for applicationName:\""
                + applicationName + "\", page:\"" + pageName, e);
    }

    return resultList.map(t -> {
        PageExperiment.Builder builder = new PageExperiment.Builder(Experiment.ID.valueOf(t.getExperimentId()),
                null, t.isAssign());
        return builder.build();
    }).collect(Collectors.toList());
}

From source file:org.obiba.mica.dataset.service.CollectedDatasetService.java

public List<DatasetVariable> processVariablesForStudyDataset(StudyDataset dataset,
        Iterable<DatasetVariable> variables) {
    if (!dataset.hasStudyTable()) {
        return Lists.newArrayList(variables);
    }/* ww w  .  j ava 2 s. com*/

    StudyTable studyTable = dataset.getStudyTable();

    BaseStudy study = studyService.findStudy(dataset.getStudyTable().getStudyId());
    Population population = study.findPopulation(studyTable.getPopulationId());

    if (population == null) {
        return Lists.newArrayList(variables);
    }

    int populationWeight = population.getWeight();

    DataCollectionEvent dataCollectionEvent = population
            .findDataCollectionEvent(studyTable.getDataCollectionEventId());

    if (dataCollectionEvent == null) {
        return Lists.newArrayList(variables);
    }

    int dataCollectionEventWeight = dataCollectionEvent.getWeight();

    return StreamSupport.stream(variables.spliterator(), false).map(datasetVariable -> {
        datasetVariable.setPopulationWeight(populationWeight);
        datasetVariable.setDataCollectionEventWeight(dataCollectionEventWeight);

        return datasetVariable;
    }).collect(toList());
}

From source file:org.talend.dataprep.api.service.FolderAPITest.java

@Test
public void shouldFolderMetadataWithHierarchy() throws Exception {
    // given//w  w w .ja  va2s  .  c om
    //                        HOME
    //              ___________|____________
    //              |                       |
    //             first                  second
    //          ____|____                   |
    //          |        |                  |
    //first child 1   first child 2     second child
    //                                      |
    //                                      |
    //                                  second child child

    createFolder("first", home.getId());
    createFolder("second", home.getId());

    final Folder firstFolder = getFolder(home.getId(), "first");
    final Folder secondFolder = getFolder(home.getId(), "second");
    createFolder("first child one", firstFolder.getId());
    createFolder("first child two", firstFolder.getId());
    createFolder("second child", secondFolder.getId());

    final Folder secondChildFolder = getFolder(secondFolder.getId(), "second child");
    createFolder("second child child", secondChildFolder.getId());

    final Folder firstChildTwo = getFolder(firstFolder.getId(), "first child two");

    // when
    final Response response = given() //
            .expect().statusCode(200).log().ifError()//
            .when() //
            .get("/folders/{id}", firstChildTwo.getId());

    // then
    final FolderInfo infos = mapper.readValue(response.asString(), new TypeReference<FolderInfo>() {
    });
    final List<Folder> hierarchy = StreamSupport.stream(infos.getHierarchy().spliterator(), false)
            .collect(toList());
    assertThat(infos.getFolder(), equalTo(firstChildTwo));
    assertThat(hierarchy, hasSize(2));
    assertThat(hierarchy.get(0).getId(), equalTo(home.getId()));
    assertThat(hierarchy.get(1).getId(), equalTo(firstFolder.getId()));
}

From source file:org.pentaho.platform.plugin.services.exporter.PentahoPlatformExporter.java

protected void exportMondrianSchemas() {
    log.debug("export mondrian schemas");

    // Get the mondrian catalogs available in the repo
    List<MondrianCatalog> catalogs = getMondrianCatalogService().listCatalogs(getSession(), false);
    for (MondrianCatalog catalog : catalogs) {

        // get the files for this catalog
        Map<String, InputStream> files = getMondrianCatalogRepositoryHelper()
                .getModrianSchemaFiles(catalog.getName());

        ExportManifestMondrian mondrian = new ExportManifestMondrian();
        for (String fileName : files.keySet()) {

            // write the file to the zip
            String path = ANALYSIS_PATH_IN_ZIP + catalog.getName() + "/" + fileName;
            ZipEntry zipEntry = new ZipEntry(new ZipEntry(ExportFileNameEncoder.encodeZipPathName(path)));
            InputStream inputStream = files.get(fileName);

            // ignore *.annotated.xml files, they are not needed
            if (fileName.equals("schema.annotated.xml")) {
                // these types of files only exist for contextual export of a data source (from the UI) to later be imported in.
                // However, in the case of backup/restore we don't need these since we'll be using the annotations.xml file along
                // with the original schema xml file to re-generate the model properly
                continue;
            } else if (MondrianVfs.ANNOTATIONS_XML.equals(fileName)) {
                // annotations.xml should be written to the zip file and referenced in the export manifest entry for the
                // related mondrian model
                mondrian.setAnnotationsFile(path);
            } else {
                // must be a true mondrian model
                mondrian.setCatalogName(catalog.getName());
                boolean xmlaEnabled = parseXmlaEnabled(catalog.getDataSourceInfo());
                mondrian.setXmlaEnabled(xmlaEnabled);
                mondrian.setFile(path);/*ww  w  .  j  ava2s .c o  m*/
                Parameters mondrianParameters = new Parameters();
                mondrianParameters.put("Provider", "mondrian");
                //DataSource can be escaped
                mondrianParameters.put("DataSource", StringEscapeUtils.unescapeXml(catalog.getJndi()));
                mondrianParameters.put("EnableXmla", Boolean.toString(xmlaEnabled));

                StreamSupport.stream(catalog.getConnectProperties().spliterator(), false)
                        .filter(p -> !mondrianParameters.containsKey(p.getKey()))
                        //if value is escaped it should be unescaped to avoid double escape after export in xml file, because
                        //marshaller executes escaping as well
                        .forEach(p -> mondrianParameters.put(p.getKey(),
                                StringEscapeUtils.unescapeXml(p.getValue())));

                mondrian.setParameters(mondrianParameters);
            }

            try {
                zos.putNextEntry(zipEntry);
                IOUtils.copy(inputStream, zos);
            } catch (IOException e) {
                log.warn(e.getMessage(), e);
            } finally {
                IOUtils.closeQuietly(inputStream);
                try {
                    zos.closeEntry();
                } catch (IOException e) {
                    // can't close the entry of input stream
                }
            }
        }
        if (mondrian.getCatalogName() != null && mondrian.getFile() != null) {
            getExportManifest().addMondrian(mondrian);
        }
    }
}

From source file:com.ikanow.aleph2.management_db.mongodb.services.IkanowV1SyncService_PurgeBuckets.java

/**
 * Returns back all purge sources that aren't marked as complete or errored,
 * deletes everything that was pulled back
 * //w  w  w. j  a  va  2s  .  c om
 * @param source_test_db
 * @return
 */
protected CompletableFuture<List<PurgeQueueBean>> getAllPurgeSources(
        final ICrudService<PurgeQueueBean> source_test_db) {
    final QueryComponent<PurgeQueueBean> get_query = CrudUtils.allOf(PurgeQueueBean.class)
            .whenNot(PurgeQueueBean::status, PurgeStatus.complete)
            .whenNot(PurgeQueueBean::status, PurgeStatus.error); //can be complete | error | in_progress | submitted | {unset/anything else}

    final CompletableFuture<List<PurgeQueueBean>> get_command = source_test_db.getObjectsBySpec(get_query)
            .thenApply(c -> StreamSupport.stream(c.spliterator(), false).collect(Collectors.toList()));

    return get_command.thenCompose(__ -> {
        return source_test_db.deleteObjectBySpec(get_query);
    }).thenApply(__ -> get_command.join()); // (ie return the original command but only once the update has completed)
}

From source file:org.obiba.mica.dataset.service.HarmonizedDatasetService.java

@Override
public Iterable<DatasetVariable> getDatasetVariables(HarmonizationDataset dataset)
        throws NoSuchValueTableException {
    return StreamSupport.stream(getVariables(dataset).spliterator(), false)
            .map(input -> new DatasetVariable(dataset, input)).collect(toList());
}

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

/**
 * Handle a magic '%functions'.  Lists all of the variables in-scope.
 * @param expression//w  w w . j  a  va  2 s. c o m
 */
private void handleMagicFunctions(String[] expression) {

    // if '%functions FOO' then show only functions that contain 'FOO'
    Predicate<String> nameFilter = (name -> true);
    if (expression.length > 1) {
        nameFilter = (name -> name.contains(expression[1]));
    }

    // '%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(", "));
    writeLine(functions);
}

From source file:org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate.java

@Override
public void deleteAll(Iterable objects) {
    applyDeleteMutations(objects, (List<Mutation>) StreamSupport.stream(objects.spliterator(), false)
            .map(this.mutationFactory::delete).collect(Collectors.toList()));
}

From source file:org.obiba.mica.dataset.service.CollectedDatasetService.java

@Override
public Iterable<DatasetVariable> getDatasetVariables(StudyDataset dataset) {
    if (dataset.hasStudyTable()) {
        return StreamSupport.stream(getVariables(dataset).spliterator(), false)
                .map(input -> new DatasetVariable(dataset, input)).collect(toList());
    }//from  ww  w.  java  2 s.c  om
    return Lists.newArrayList();
}

From source file:it.qualityGate.QualityGateTest.java

private static List<String> extractPosttaskPluginLogs(String taskUuid, Iterable<String> ceLogs) {
    return StreamSupport.stream(ceLogs.spliterator(), false)
            .filter(s -> s.contains("POSTASKPLUGIN: finished()")).filter(s -> s.contains(taskUuid))
            .collect(Collectors.toList());
}