Example usage for java.util Collection stream

List of usage examples for java.util Collection stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:org.n52.youngs.test.ElasticsearchSinkCswMappingIT.java

@Test
public void store() throws Exception {
    Collection<SourceRecord> records = SourceRecordHelper.loadGetRecordsResponse(
            Resources.asByteSource(Resources.getResource("responses/dab-records-csw.xml")).openStream());
    List<SinkRecord> mappedRecords = records.stream().map(mapper::map).collect(Collectors.toList());

    boolean stored = sink.store(mappedRecords);
    Thread.sleep(1000);// w w  w.  j  a va2s  .c om
    assertThat("all records stored", stored);

    String query = "http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType()
            + "/_search?q=*&size=100";
    String searchAllResponse = Request.Get(query).execute().returnContent().asString();
    assertThat("all records were added to the index", searchAllResponse,
            hasJsonPath("hits.total", is(mappedRecords.size())));
    assertThat("ids are contains", searchAllResponse,
            allOf(containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METOP:NRP"),
                    containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METOP:SEM"),
                    containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:MFG:CDS-IODC"),
                    containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:MULT:FDN"),
                    containsString("urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METEOSAT:OSIDSSI")));

    String id = "urn:x-wmo:md:int.eumetsat::EO:EUM:DAT:METOP:ORBITVIEW";
    String recordResponse = Request
            .Get("http://localhost:9200/" + mapping.getIndex() + "/" + mapping.getType() + "/" + id).execute()
            .returnContent().asString();
    assertThat("record is in index", recordResponse, hasJsonPath("_index", is(equalTo(mapping.getIndex()))));
    assertThat("record is found", recordResponse, hasJsonPath("_id", is(id)));
    assertThat("record is found", recordResponse, hasJsonPath("_source.type", is("series")));
}

From source file:com.teradata.benchto.driver.loader.BenchmarkLoader.java

private String createFormatString(Collection<Benchmark> benchmarks) {
    int nameMaxLength = benchmarks.stream().mapToInt((benchmark) -> benchmark.getName().length()).max()
            .orElseGet(() -> 10);//from   www .  ja  va  2 s.c  om
    int dataSourceMaxLength = benchmarks.stream().mapToInt((benchmark) -> benchmark.getDataSource().length())
            .max().orElseGet(() -> 10);
    int indent = 3;
    return "\t| %-" + (nameMaxLength + indent) + "s | %-" + (dataSourceMaxLength + indent)
            + "s | %-4s | %-8s | %-11s |";
}

From source file:bjerne.gallery.service.impl.GalleryAuthorizationServiceSSImpl.java

private Collection<String> getCurrentUserRoles() {
    Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication()
            .getAuthorities();/*  w  w w .  j  av a 2 s . c o m*/
    Collection<String> currentUserRoles = authorities.stream().map(e -> e.getAuthority())
            .collect(Collectors.toSet());
    LOG.debug("Roles for current user: {}", currentUserRoles);
    return currentUserRoles;
}

From source file:com.hortonworks.streamline.registries.dashboard.service.DashboardCatalogService.java

public Set<Long> getWidgetDatasourceMapping(Widget widget) {
    List<QueryParam> queryParams = Collections
            .singletonList(new QueryParam(WidgetDatasourceMapping.WIDGET_ID, widget.getId().toString()));
    Collection<WidgetDatasourceMapping> mappings = dao.find(WIDGET_DATASOURCE_MAPPING_NAMESPACE, queryParams);
    if (mappings != null) {
        return mappings.stream().map(WidgetDatasourceMapping::getWidgetId).collect(Collectors.toSet());
    }//from  w w w. jav  a  2  s  .  c  om
    return Collections.emptySet();
}

From source file:uk.dsxt.voting.client.ClientManager.java

public RequestResult getAllClientVotes(String votingId) {
    List<VoteResultWeb> results = new ArrayList<>();
    final Collection<VoteResultAndStatus> votes = assetsHolder.getClientVotes(votingId);
    results.addAll(votes.stream().map(VoteResultWeb::new).collect(Collectors.toList()));
    return new RequestResult<>(results.toArray(new VoteResultWeb[results.size()]), null);
}

From source file:com.yahoo.elide.core.hibernate.hql.AbstractHQLQueryBuilder.java

/**
 * Extracts all the HQL JOIN clauses from given filter expression.
 * @param filterExpression the filter expression to extract a join clause from
 * @return an HQL join clause//  w  w  w.ja va  2s  .  com
 */
protected String getJoinClauseFromFilters(FilterExpression filterExpression) {
    PredicateExtractionVisitor visitor = new PredicateExtractionVisitor(new ArrayList<>());
    Collection<FilterPredicate> predicates = filterExpression.accept(visitor);

    Set<String> alreadyJoined = new HashSet<>();

    return predicates.stream().map(predicate -> extractJoinClause(predicate, alreadyJoined))
            .collect(Collectors.joining(SPACE));
}

From source file:com.devicehive.dao.riak.UserDaoRiakImpl.java

@Override
public List<UserVO> list(String login, String loginPattern, Integer role, Integer status, String sortField,
        Boolean isSortOrderAsc, Integer take, Integer skip) {

    BucketMapReduce.Builder builder = new BucketMapReduce.Builder().withNamespace(USER_NS);
    addMapValues(builder);/*w ww .  java  2s  . c  o  m*/
    if (login != null) {
        addReduceFilter(builder, "login", FilterOperator.EQUAL, login);
    } else if (loginPattern != null) {
        loginPattern = loginPattern.replace("%", "");
        addReduceFilter(builder, "login", FilterOperator.REGEX, loginPattern);
    }
    if (role != null) {
        String roleString = UserRole.getValueForIndex(role).name();
        addReduceFilter(builder, "role", FilterOperator.EQUAL, roleString);
    }
    if (status != null) {
        String statusString = UserStatus.getValueForIndex(status).name();
        addReduceFilter(builder, "status", FilterOperator.EQUAL, statusString);
    }

    addReduceSort(builder, sortField, isSortOrderAsc);
    addReducePaging(builder, true, take, skip);
    try {
        MapReduce.Response response = client.execute(builder.build());
        Collection<RiakUser> users = response.getResultsFromAllPhases(RiakUser.class);
        return users.stream().map(RiakUser::convertToVo).collect(Collectors.toList());
    } catch (InterruptedException | ExecutionException e) {
        throw new HivePersistenceLayerException("Cannot execute search user.", e);
    }
}

From source file:ddf.catalog.validation.impl.validator.RelationshipValidator.java

private Optional<ValidationViolation> cannotHave(Collection<String> actualValues) {
    boolean isViolated;
    if (targetValues.isEmpty()) {
        isViolated = !actualValues.isEmpty();
    } else {//from  w  w w.ja  v a2 s. com
        isViolated = actualValues.stream().anyMatch(targetValues::contains);
    }
    return getValidationViolation("cannot have", isViolated);
}

From source file:com.netflix.spinnaker.fiat.roles.ldap.LdapUserRolesProvider.java

@Override
public Map<String, Collection<Role>> multiLoadRoles(Collection<String> userIds) {
    if (StringUtils.isEmpty(configProps.getGroupSearchBase())) {
        return new HashMap<>();
    }//w w  w.j  a v a2s .c  o m

    // ExternalUser is used here as a simple data type to hold the username/roles combination.
    return userIds.stream().map(userId -> new ExternalUser().setId(userId).setExternalRoles(loadRoles(userId)))
            .collect(Collectors.toMap(ExternalUser::getId, ExternalUser::getExternalRoles));
}

From source file:be.ordina.msdashboard.graph.RedisServiceTest.java

@Test
public void getAllNodes() {
    Set<String> keys = Collections.singleton("nodeId");

    doReturn(keys).when(redisTemplate).keys("virtual:*");

    ValueOperations opsForValue = mock(ValueOperations.class);

    doReturn(opsForValue).when(redisTemplate).opsForValue();

    Node node = new Node("redisnode");

    doReturn(node).when(opsForValue).get("nodeId");

    Collection<Node> nodes = redisService.getAllNodes();

    verify(redisTemplate).keys("virtual:*");
    verify(redisTemplate).opsForValue();
    verify(opsForValue).get("nodeId");

    assertThat(nodes).isNotEmpty();/* ww w .  j av  a 2 s.  co m*/
    assertThat(nodes.stream().findFirst().get()).isEqualTo(node);
}