Example usage for java.util Spliterators spliteratorUnknownSize

List of usage examples for java.util Spliterators spliteratorUnknownSize

Introduction

In this page you can find the example usage for java.util Spliterators spliteratorUnknownSize.

Prototype

public static Spliterator.OfDouble spliteratorUnknownSize(PrimitiveIterator.OfDouble iterator,
        int characteristics) 

Source Link

Document

Creates a Spliterator.OfDouble using a given DoubleStream.DoubleIterator as the source of elements, with no initial size estimate.

Usage

From source file:org.apache.tinkerpop.gremlin.process.traversal.Traversal.java

/**
 * Return the traversal as a {@link Stream}.
 *
 * @return the traversal as a stream./*from  w  ww. j a v  a 2  s  .  c  o m*/
 */
public default Stream<E> toStream() {
    return StreamSupport.stream(
            Spliterators.spliteratorUnknownSize(this, Spliterator.IMMUTABLE | Spliterator.SIZED), false);
}

From source file:com.bouncestorage.swiftproxy.v1.ObjectResource.java

private List<Pair<Long, Long>> parseRange(String range) {
    range = range.replaceAll(" ", "").toLowerCase();
    String bytesUnit = "bytes=";
    int idx = range.indexOf(bytesUnit);
    if (idx == 0) {
        String byteRangeSet = range.substring(bytesUnit.length());
        Iterator<Object> iter = Iterators.forEnumeration(new StringTokenizer(byteRangeSet, ","));
        return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED), false)
                .map(rangeSpec -> (String) rangeSpec).map(rangeSpec -> {
                    int dash = rangeSpec.indexOf("-");
                    if (dash == -1) {
                        throw new BadRequestException("Range");
                    }//ww w  .j a  v a 2s .  co  m
                    String firstBytePos = rangeSpec.substring(0, dash);
                    String lastBytePos = rangeSpec.substring(dash + 1);
                    Long firstByte = firstBytePos.isEmpty() ? null : Long.parseLong(firstBytePos);
                    Long lastByte = lastBytePos.isEmpty() ? null : Long.parseLong(lastBytePos);
                    return new Pair<>(firstByte, lastByte);
                }).peek(r -> logger.debug("parsed range {} {}", r.getFirst(), r.getSecond()))
                .collect(Collectors.toList());
    } else {
        return null;
    }
}

From source file:ai.grakn.migration.csv.CSVMigrator.java

/**
 * Partition a stream into a stream of collections, each with batchSize elements.
 * @param iterator Iterator to partition
 * @param <T> Type of values of iterator
 * @return Stream over a collection that are each of batchSize
 *//*ww  w .  j  a v  a 2  s.co m*/
protected <T> Stream<T> stream(Iterator<T> iterator) {
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false);

}

From source file:notaql.performance.PerformanceTest.java

private static String composeEngine(JSONObject engine) {
    final StringBuilder builder = new StringBuilder();
    builder.append(engine.get("engine"));
    builder.append("(");

    final String params = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(engine.keys(), Spliterator.ORDERED), false)
            .filter(k -> !k.equals("engine")).map(k -> k + " <- " + toArg(k, engine))
            .collect(Collectors.joining(", "));

    builder.append(params);//from  w ww .  ja  v a 2s.co  m
    builder.append(")");

    return builder.toString();
}

From source file:com.uber.hoodie.utilities.sources.KafkaSource.java

public KafkaSource(PropertiesConfiguration config, JavaSparkContext sparkContext, SourceDataFormat dataFormat,
        SchemaProvider schemaProvider) {
    super(config, sparkContext, dataFormat, schemaProvider);

    kafkaParams = new HashMap<>();
    Stream<String> keys = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(config.getKeys(), Spliterator.NONNULL), false);
    keys.forEach(k -> kafkaParams.put(k, config.getString(k)));

    UtilHelpers.checkRequiredProperties(config, Arrays.asList(Config.KAFKA_TOPIC_NAME));
    topicName = config.getString(Config.KAFKA_TOPIC_NAME);
}

From source file:org.nuxeo.ecm.automation.DetachTemplateFromAllDocuments.java

protected List<String> getDocumentsWithTemplate(CoreSession session, String query) {
    List<String> ids = new ArrayList<String>();
    IterableQueryResult it = null;//from w w  w  .  j  a va 2 s.c  om
    try {
        it = session.queryAndFetch(query, NXQL);
        Spliterator<Map<String, Serializable>> spliterator = Spliterators.spliteratorUnknownSize(it.iterator(),
                Spliterator.NONNULL);
        ids = StreamSupport.stream(spliterator, false).map(map -> (String) map.get(ECM_UUID))
                .collect(Collectors.toList());
    } finally {
        if (it != null) {
            it.close();
        }
    }
    return ids;
}

From source file:com.yevster.spdxtra.Read.java

private static Stream<Relationship> getRelationshipsWithSparql(Dataset dataset, String sparql) {
    try (DatasetAutoAbortTransaction transaction = DatasetAutoAbortTransaction.begin(dataset, ReadWrite.READ)) {
        QueryExecution qe = QueryExecutionFactory.create(sparql, dataset);
        ResultSet results = qe.execSelect();
        Stream<QuerySolution> solutionStream = StreamSupport.stream(
                Spliterators.spliteratorUnknownSize(results, Spliterator.ORDERED | Spliterator.NONNULL), false);

        return solutionStream.map((QuerySolution qs) -> {
            RDFNode relationshipNode = qs.get("o");
            assert (relationshipNode.isResource());
            return new Relationship(relationshipNode.asResource());
        });/*from   w ww .  j  a v  a 2s  .c o m*/

    }
}

From source file:org.jsonschema2pojo.rules.AdditionalPropertiesRule.java

private JMethod addInnerBuilder(JDefinedClass jclass, JType propertyType, JFieldVar field) {
    Optional<JDefinedClass> builderClass = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(jclass.classes(), Spliterator.ORDERED), false)
            .filter(definedClass -> definedClass.name().equals(getBuilderClassName(jclass))).findFirst();

    JMethod builder = builderClass.get().method(JMod.PUBLIC, builderClass.get(), "withAdditionalProperty");

    JVar nameParam = builder.param(String.class, "name");
    JVar valueParam = builder.param(propertyType, "value");

    JBlock body = builder.body();//from w  ww. j a va2 s .co  m
    JInvocation mapInvocation = body.invoke(JExpr.ref(JExpr.cast(jclass, JExpr._this().ref("instance")), field),
            "put");
    mapInvocation.arg(nameParam);
    mapInvocation.arg(valueParam);
    body._return(JExpr._this());

    return builder;
}

From source file:org.apache.nifi.minifi.c2.provider.nifi.rest.NiFiRestConfigurationProvider.java

private Pair<Stream<Pair<String, String>>, Closeable> getIdAndFilenameStream()
        throws ConfigurationProviderException, IOException {
    TemplatesIterator templatesIterator = new TemplatesIterator(httpConnector, jsonFactory);
    return new Pair<>(StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(templatesIterator, Spliterator.ORDERED), false),
            templatesIterator);/*from  w ww.j a v a 2 s.co  m*/
}

From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java

Stream<AppPage> getAppPagesFromCassandra(Application.Name applicationName) {
    Optional<Iterator<AppPage>> optionalResult = Optional.empty();
    try {/*from  ww w. jav a2s  .c o  m*/
        optionalResult = Optional
                .ofNullable(appPageIndexAccessor.selectBy(applicationName.toString()).iterator());
    } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) {
        throw new RepositoryException(
                "Could not retrieve the pages and its associated experiments for application:\""
                        + applicationName + "\"",
                e);
    }
    return StreamSupport.stream(Spliterators.spliteratorUnknownSize(
            optionalResult.orElse(Collections.emptyIterator()), Spliterator.ORDERED), false);
}