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.talend.dataprep.preparation.service.PreparationControllerTest.java

private void checkSearchByName(String name, boolean exactMatch, List<String> expectedIds) throws IOException {
    // when/*from  w  w w.ja  v a  2  s.  c o m*/
    final Response response = given() //
            .queryParam("name", name) //
            .queryParam("exactMatch", exactMatch) //
            .queryParam("sort", "creationDate") //
            .queryParam("order", "asc") //
            .when().expect().statusCode(200).log().ifError() //
            .get("/preparations/search");

    // then
    assertThat(response.getStatusCode(), is(200));
    final JsonNode rootNode = mapper.reader().readTree(response.asInputStream());
    assertTrue(rootNode.isArray());
    assertEquals(expectedIds.size(), rootNode.size());
    final List<String> actualIds = StreamSupport.stream(rootNode.spliterator(), false)
            .map(n -> n.get("id").asText()).collect(Collectors.toList());
    assertEquals(expectedIds.size(), actualIds.stream().filter(expectedIds::contains).count());
}

From source file:org.mascherl.example.service.ComposeMailService.java

public Observable<MailAddressUsage> getLastSendToAddressesAsync(User currentUser, int limit) {
    return Observable.<MailAddressUsage>create((subscriber) -> {
        db.query(//  w w w.  j  a v  a 2  s.c  o  m
                "select distinct mto.address, m.datetime " + "from mail m "
                        + "join mail_to mto on mto.mail_uuid = m.uuid " + "where m.user_uuid = $1 "
                        + "and m.mail_type = $2 " + "and not exists (" + "   select 1 from mail m2 "
                        + "   join mail_to mto2 on mto2.mail_uuid = m2.uuid " + "   where m2.user_uuid = $1 "
                        + "   and m2.mail_type = $2 " + "   and mto2.address = mto.address "
                        + "   and m2.datetime > m.datetime " + ") " + "order by m.datetime desc " + "limit $3",
                Arrays.asList(currentUser.getUuid(), MailType.SENT.name(), limit), result -> {
                    try {
                        subscriber.onStart();
                        TimestampColumnZonedDateTimeMapper dateTimeColumnMapper = new PersistentZonedDateTime()
                                .getColumnMapper();
                        StreamSupport.stream(result.spliterator(), false)
                                .map(row -> new MailAddressUsage(new MailAddress(row.getString(0)),
                                        dateTimeColumnMapper.fromNonNullValue(row.getTimestamp(1))))
                                .forEach(subscriber::onNext);
                        subscriber.onCompleted();
                    } catch (Exception e) {
                        subscriber.onError(e);
                    }
                }, subscriber::onError);
    });
}

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

/**
 * Handles user interaction when executing a doc command.
 * @param expression The expression to execute.
 *//*w  w  w .  j a v  a 2s  .c o  m*/
private void handleDoc(String expression) {

    String functionName = StringUtils.substring(expression, 1);
    StreamSupport.stream(executor.getFunctionResolver().getFunctionInfo().spliterator(), false)
            .filter(info -> StringUtils.equals(functionName, info.getName())).map(info -> format(info))
            .forEach(doc -> write(doc));
}

From source file:org.geowebcache.s3.S3Ops.java

public Stream<S3ObjectSummary> objectStream(String prefix) {
    return StreamSupport.stream(S3Objects.withPrefix(conn, bucketName, prefix).spliterator(), false);
}

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

private List<LinkIssuesInput> calculateNewLinks(Issue issue,
        com.atlassian.jira.rest.client.api.domain.Issue jiraIssue) {
    // When jiraIssueLinks is null, this means that issue links have been disabled, so return an empty list
    Iterable<IssueLink> jiraIssueLinks = jiraIssue.getIssueLinks();
    if (jiraIssueLinks == null)
        return new ArrayList<>();

    // Process the existing IssueLinks and retrieve their Issue keys
    List<IssueLink> tmp = StreamSupport.stream(jiraIssueLinks.spliterator(), false)
            .collect(Collectors.toList());
    List<String> inbound = getExistingIssueLinkKeys(tmp, Direction.INBOUND);
    List<String> outbound = getExistingIssueLinkKeys(tmp, Direction.OUTBOUND);

    return Stream.concat(
            createIssueLinks(issue, inbound, e -> new LinkIssuesInput(e, jiraIssue.getKey(), "Dependency")),
            createIssueLinks(issue, outbound, e -> new LinkIssuesInput(jiraIssue.getKey(), e, "Dependency")))
            .collect(Collectors.toList());
}

From source file:org.onosproject.ecord.carrierethernet.app.CarrierEthernetPacketNodeManager.java

@Override
public void applyBandwidthProfileResources(CarrierEthernetForwardingConstruct fc, CarrierEthernetUni uni) {

    DeviceId deviceId = uni.cp().deviceId();

    // Do not apply meters to NETCONF-controlled switches here since they should have been applied in the pipeline
    // FIXME: Is there a better way to check this?
    if (deviceId.uri().getScheme().equals("netconf")) {
        return;/*from  w w w . j av  a  2s.  c o m*/
    }

    Dpid dpid = Dpid.dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);

    // Do not apply meters to OFDPA 2.0 switches since they are not currently supported
    if (sw.softwareDescription().equals("OF-DPA 2.0")) {
        return;
    }

    // Get installed flows with the same appId/deviceId with IN_PORT = UNI port which push the FC vlanId
    List<FlowRule> flowRuleList = StreamSupport
            .stream(flowRuleService.getFlowEntries(deviceId).spliterator(), false)
            .filter(flowRule -> flowRule.appId() == appId.id()
                    && getPushedVlanFromTreatment(flowRule.treatment()).equals(fc.vlanId())
                    && getInPortNumberFromSelector(flowRule.selector()).equals(uni.cp().port()))
            .collect(Collectors.toList());

    // Apply meters to flows
    for (FlowRule flowRule : flowRuleList) {
        // Need to add to the flow the meters associated with the same device
        Set<DeviceMeterId> tmpDeviceMeterIdSet = new HashSet<>();
        deviceMeterIdMap.get(fc.id()).forEach(deviceMeterId -> {
            if (deviceMeterId.deviceId().equals(flowRule.deviceId())) {
                tmpDeviceMeterIdSet.add(deviceMeterId);
            }
        });
        // Modify and submit flow rule only if there are meters to add
        if (!tmpDeviceMeterIdSet.isEmpty()) {
            FlowRule newFlowRule = addMetersToFlowRule(flowRule, tmpDeviceMeterIdSet);
            flowRuleService.applyFlowRules(newFlowRule);
        }
    }
}

From source file:org.briljantframework.array.AbstractComplexArray.java

@Override
public Stream<Complex> stream() {
    return StreamSupport.stream(Spliterators.spliterator(new Iterator<Complex>() {
        int current = 0;

        @Override//from w w w .ja  v a2  s  .co  m
        public boolean hasNext() {
            return current < size();
        }

        @Override
        public Complex next() {
            return get(current++);
        }
    }, size(), Spliterator.SIZED), false);
}

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

@Override
public void complete(final EncryptedMultipartUpload<WRAPPED_UPLOAD> upload,
        final Iterable<? extends MantaMultipartUploadTuple> parts) throws IOException {
    try (Stream<? extends MantaMultipartUploadTuple> stream = StreamSupport.stream(parts.spliterator(),
            false)) {//from   w w w.  j ava  2s . co m
        complete(upload, stream);
    }
}

From source file:org.briljantframework.array.AbstractBooleanArray.java

@Override
public Stream<Boolean> stream() {
    return StreamSupport.stream(Spliterators.spliterator(new Iterator<Boolean>() {
        int current = 0;

        @Override//from  www.  j  a  va  2 s .c  o  m
        public boolean hasNext() {
            return current < size();
        }

        @Override
        public Boolean next() {
            return get(current++);
        }
    }, size(), Spliterator.SIZED), false);
}

From source file:fi.vm.sade.eperusteet.ylops.service.ops.impl.OpetussuunnitelmaServiceImpl.java

@Override
@Transactional(readOnly = true)/*from   w  w  w  . j av a 2s .co  m*/
public List<OpetussuunnitelmaJulkinenDto> getAllJulkiset(OpetussuunnitelmaQuery query) {
    List<Opetussuunnitelma> opetussuunnitelmat;
    if (query != null) {
        query.setTyyppi(Tyyppi.OPS);
        opetussuunnitelmat = findByQuery(query).stream().filter(ops -> ops.getTila() == Tila.JULKAISTU)
                .collect(Collectors.toList());
    } else {
        opetussuunnitelmat = repository.findAllByTyyppiAndTilaIsJulkaistu(Tyyppi.OPS);
    }

    final List<OpetussuunnitelmaJulkinenDto> dtot = mapper.mapAsList(opetussuunnitelmat,
            OpetussuunnitelmaJulkinenDto.class);

    dtot.forEach(dto -> {
        for (KoodistoDto koodistoDto : dto.getKunnat()) {
            Map<String, String> tekstit = new HashMap<>();
            KoodistoKoodiDto kunta = koodistoService.get("kunta", koodistoDto.getKoodiUri());
            if (kunta != null) {
                for (KoodistoMetadataDto metadata : kunta.getMetadata()) {
                    tekstit.put(metadata.getKieli(), metadata.getNimi());
                }
            }
            koodistoDto.setNimi(new LokalisoituTekstiDto(tekstit));
        }

        for (OrganisaatioDto organisaatioDto : dto.getOrganisaatiot()) {
            Map<String, String> tekstit = new HashMap<>();
            List<String> tyypit = new ArrayList<>();
            JsonNode organisaatio = organisaatioService.getOrganisaatio(organisaatioDto.getOid());
            if (organisaatio != null) {
                JsonNode nimiNode = organisaatio.get("nimi");
                if (nimiNode != null) {
                    Iterator<Map.Entry<String, JsonNode>> it = nimiNode.fields();
                    while (it.hasNext()) {
                        Map.Entry<String, JsonNode> field = it.next();
                        tekstit.put(field.getKey(), field.getValue().asText());
                    }
                }

                JsonNode tyypitNode = Optional.ofNullable(organisaatio.get("tyypit"))
                        .orElse(organisaatio.get("organisaatiotyypit"));
                if (tyypitNode != null) {
                    tyypit = StreamSupport.stream(tyypitNode.spliterator(), false).map(JsonNode::asText)
                            .collect(Collectors.toList());
                }
            }
            organisaatioDto.setNimi(new LokalisoituTekstiDto(tekstit));
            organisaatioDto.setTyypit(tyypit);
        }
    });
    return dtot;
}