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:org.hawkular.metrics.dropwizard.HawkularReporterTest.java

@Test
public void shouldReportBigIntegerGauge() {
    HawkularReporter reporter = HawkularReporter.builder(registry, "unit-test").useHttpClient(uri -> client)
            .build();//from   ww  w .  j a  v a2s .  c om

    final Gauge<BigInteger> gauge = () -> new BigInteger("2");
    registry.register("gauge.bigi", gauge);
    reporter.report();

    assertThat(client.getMetricsRestCalls()).hasSize(1);
    JSONObject metrics = new JSONObject(client.getMetricsRestCalls().get(0));
    assertThat(metrics.keySet()).containsOnly("gauges");

    JSONArray gaugesJson = metrics.getJSONArray("gauges");
    Map<String, Double> values = StreamSupport.stream(gaugesJson.spliterator(), false)
            .collect(toMap(idFromRoot::extract, dValueFromRoot::extract));
    assertThat(values).containsOnly(entry("gauge.bigi", 2d));
}

From source file:fr.landel.utils.assertor.utils.AssertorIterable.java

private static <I extends Iterable<T>, T> boolean has(final I iterable1, final Iterable<T> iterable2,
        final boolean all, final boolean not, final EnumAnalysisMode analysisMode) {

    final int size2 = IterableUtils.size(iterable2);

    if (all && !not && size2 > IterableUtils.size(iterable1)) {
        return false;
    }/*from w w w  .  j  a v  a  2 s  .c om*/

    if (EnumAnalysisMode.STANDARD.equals(analysisMode)) {
        if (all && !not) {
            for (final T objectRef : iterable2) {
                if (!AssertorIterable.has(iterable1, objectRef, analysisMode)) {
                    return false;
                }
            }
            return true;
        } else if (!all) { // any and not any
            for (final T objectRef : iterable2) {
                if (AssertorIterable.has(iterable1, objectRef, analysisMode)) {
                    return !not;
                }
            }
            return not;
        } else { // not all
            long found = 0;
            for (final T objectRef : iterable2) {
                if (AssertorIterable.has(iterable1, objectRef, analysisMode)) {
                    ++found;
                }
            }
            return HelperAssertor.isValid(all, not, found, size2);
        }

    } else {
        return HelperAssertor.isValid(
                StreamSupport.stream(iterable2.spliterator(), EnumAnalysisMode.PARALLEL.equals(analysisMode)),
                o -> AssertorIterable.has(iterable1, o, analysisMode), all, not, () -> size2);
    }
}

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

/** Gets a list of _id,modified from v1 and a list matching _id,modified from V2
 * @param library_mgmt// w ww.  j a  v  a 2  s.  c o m
 * @param share_db
 * @return tuple of id-vs-(date-or-null-if-not-approved) for v1, id-vs-date for v2
 */
protected static CompletableFuture<Tuple2<Map<String, String>, Map<String, Date>>> compareJarsToLibaryBeans_get(
        final IManagementCrudService<SharedLibraryBean> library_mgmt, final ICrudService<JsonNode> share_db) {
    // (could make this more efficient by having a regular "did something happen" query with a slower "get everything and resync)
    // (don't forget to add "modified" to the compound index though)
    CompletableFuture<Cursor<JsonNode>> f_v1_jars = share_db
            .getObjectsBySpec(CrudUtils.allOf().when("type", "binary").rangeIn("title", "/app/aleph2/library/",
                    true, "/app/aleph2/library0", true), Arrays.asList(JsonUtils._ID, "modified"), true);

    return f_v1_jars.<Map<String, String>>thenApply(v1_jars -> {
        return StreamSupport.stream(v1_jars.spliterator(), false).collect(Collectors
                .toMap(j -> safeJsonGet(JsonUtils._ID, j).asText(), j -> safeJsonGet("modified", j).asText()));
    }).<Tuple2<Map<String, String>, Map<String, Date>>>thenCompose(v1_id_datestr_map -> {
        final SingleQueryComponent<SharedLibraryBean> library_query = CrudUtils.allOf(SharedLibraryBean.class)
                .rangeIn(SharedLibraryBean::_id, "v1_", true, "v1a", true);

        return library_mgmt.getObjectsBySpec(library_query, Arrays.asList(JsonUtils._ID, "modified"), true)
                .<Tuple2<Map<String, String>, Map<String, Date>>>thenApply(c -> {
                    final Map<String, Date> v2_id_date_map = StreamSupport.stream(c.spliterator(), false)
                            .collect(Collectors.toMap(b -> b._id().substring(3), //(ie remove the "v1_")
                                    b -> b.modified()));

                    return Tuples._2T(v1_id_datestr_map, v2_id_date_map);
                });
    });
}

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

private Map<String, String> getUserMetadata(Request request) {
    return StreamSupport.stream(request.getHeaderNames().spliterator(), false)
            .filter(name -> name.toLowerCase().startsWith(META_HEADER_PREFIX.toLowerCase())).filter(name -> {
                if (name.equalsIgnoreCase(META_HEADER_PREFIX) || RESERVED_METADATA.contains(name)) {
                    throw new BadRequestException();
                }/*from w ww .ja  v a  2  s . co  m*/
                if (name.length() - META_HEADER_PREFIX.length() > InfoResource.CONFIG.swift.max_meta_name_length
                        || request.getHeader(name).length() > InfoResource.CONFIG.swift.max_meta_value_length) {
                    throw new BadRequestException();
                }
                return true;
            }).collect(Collectors.toMap(name -> name.substring(META_HEADER_PREFIX.length()),
                    name -> request.getHeader(name)));
}

From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java

/** Get a set of field mappings from the "dynamic_templates" section of a mapping
 * @param index/*  w  ww. j  av  a 2  s  .  c o m*/
 * @return
 */
protected static LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode> getTemplates(
        final JsonNode index, final JsonNode default_string_mapping,
        final Set<Either<String, Tuple2<String, String>>> already_processed) {
    return Optional.ofNullable(index.get("dynamic_templates")).filter(p -> !p.isNull()).map(p -> {
        if (!p.isArray())
            throw new RuntimeException("dynamic_templates must be object");
        return p;
    }).map(p -> {
        return StreamSupport
                .stream(Spliterators.spliteratorUnknownSize(p.elements(), Spliterator.ORDERED), false)
                .map(pf -> {
                    if (!pf.isObject())
                        throw new RuntimeException("dynamic_templates[*] must be object");
                    return pf;
                })
                .flatMap(pp -> StreamSupport
                        .stream(Spliterators.spliteratorUnknownSize(pp.fields(), Spliterator.ORDERED), false))
                .filter(kv -> !kv.getKey().equals(STRING_OVERRIDE_NAME)
                        || !already_processed.contains(Either.right(Tuples._2T("*", "string")))) // (don't override a specified string)
                .map(kv -> !kv.getKey().equals(STRING_OVERRIDE_NAME) ? kv
                        : Maps.immutableEntry(kv.getKey(), default_string_mapping)) //(special case - overwrite with system default)
                .collect(
                        Collectors.<Map.Entry<String, JsonNode>, Either<String, Tuple2<String, String>>, JsonNode, LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode>>toMap(
                                kv -> Either.right(buildMatchPair(kv.getValue())), kv -> kv.getValue(),
                                (v1, v2) -> v1, // (should never happen)
                                () -> new LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode>()));
    }).orElse(new LinkedHashMap<Either<String, Tuple2<String, String>>, JsonNode>());
}

From source file:org.jboss.set.aphrodite.issue.trackers.jira.JiraIssueTracker.java

@Override
public boolean isCPReleased(String cpVersion) {
    // For Jira, only accept GA version format x.y.z.GA, e.g. 7.1.2.GA
    // ignore CR version like 7.0.7.CR3
    Matcher matcher = JIRAFIXVERSION.matcher(cpVersion);
    if (!matcher.matches()) {
        return false;
    }/*from   www . ja va  2s. c  o m*/
    Promise<Project> promise = restClient.getProjectClient().getProject("JBEAP");
    Project project = promise.claim();

    Optional<Version> version = StreamSupport.stream(project.getVersions().spliterator(), false)
            .filter(v -> v.getName().equals(cpVersion)).findAny();
    if (version.isPresent()) {
        return version.get().isReleased();
    }

    return false;
}

From source file:util.ItUtils.java

public static List<String> extractCeTaskIds(BuildResult buildResult) {
    String logs = buildResult.getLogs();
    return StreamSupport.stream(LINE_SPLITTER.split(logs).spliterator(), false)
            .filter(s -> s.contains("More about the report processing at"))
            .map(s -> s.substring(s.length() - 20, s.length())).collect(Collectors.toList());
}

From source file:com.simiacryptus.util.Util.java

/**
 * To stream stream.//from   w w w .j a  v a  2s .  c o  m
 *
 * @param <T>      the type parameter
 * @param iterator the iterator
 * @param size     the size
 * @param parallel the parallel
 * @return the stream
 */
public static <T> Stream<T> toStream(@javax.annotation.Nonnull final Iterator<T> iterator, final int size,
        final boolean parallel) {
    return StreamSupport.stream(Spliterators.spliterator(iterator, size, Spliterator.ORDERED), parallel);
}

From source file:com.joyent.manta.client.multipart.JobsMultipartManager.java

@Override
public void complete(final JobsMultipartUpload upload,
        final Iterable<? extends MantaMultipartUploadTuple> parts) throws IOException {
    Validate.notNull(upload, "Multipart upload object must not be null");

    try (Stream<? extends MantaMultipartUploadTuple> stream = StreamSupport.stream(parts.spliterator(),
            false)) {//  w  ww .  jav a  2 s  .  co m
        complete(upload, stream);
    }
}

From source file:org.jboss.set.aphrodite.issue.trackers.jira.IssueWrapper.java

private void setIssueReleases(Issue issue, com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) {
    Iterable<Version> versions = jiraIssue.getFixVersions();
    if (versions != null) {
        List<Release> releases = StreamSupport.stream(jiraIssue.getFixVersions().spliterator(), false)
                .map(version -> new Release(version.getName())).collect(Collectors.toList());
        issue.setReleases(releases);/*from   w  w  w .j  a v a  2 s .  com*/
    }
}