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:io.gravitee.repository.mongodb.management.MongoApiKeyRepository.java

private Set<ApiKey> map(Collection<ApiAssociationMongo> apiAssociationMongos) {
    if (apiAssociationMongos == null) {
        return Collections.emptySet();
    }//from  ww  w.ja  va2s .  c  om

    return apiAssociationMongos.stream().map(apiAssociationMongo -> {
        ApiKey key = mapper.map(apiAssociationMongo.getKey(), ApiKey.class);
        key.setApi(apiAssociationMongo.getApi().getId());
        key.setApplication(apiAssociationMongo.getApplication().getId());

        return key;
    }).collect(Collectors.toSet());
}

From source file:com.avanza.ymer.YmerFactory.java

public YmerFactory(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter,
        Collection<MirroredObjectDefinition<?>> definitions) {
    this.mongoDbFactory = mongoDbFactory;
    this.mongoConverter = mongoConverter;
    this.mirroredObjects = new MirroredObjects(definitions.stream());
}

From source file:org.ff4j.services.GroupServices.java

public Collection<FeatureApiBean> getFeaturesByGroup(String groupName) {
    featureValidator.assertGroupExist(groupName);
    Collection<Feature> features = ff4j.getFeatureStore().readGroup(groupName).values();
    Collection<FeatureApiBean> featureApiBeans = new ArrayList<>();
    if (!CollectionUtils.isEmpty(features)) {
        featureApiBeans.addAll(features.stream().map(FeatureApiBean::new).collect(Collectors.toList()));
    }/*ww w  .j av  a 2 s  . com*/
    return featureApiBeans;
}

From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java

/** Utility to get the vertices in the DB matching the specified keys TODO: move to intermediate utils  
 * @param keys// w  ww .  j a v a  2 s. c o  m
 * @param bucket_filter
 * @return
 */
@SuppressWarnings("unchecked")
public static final Map<JsonNode, List<Vertex>> getGroupedVertices(final Collection<ObjectNode> keys,
        final TitanTransaction tx, final List<String> key_fields, final Predicate<Vertex> vertex_filter) {
    final Stream<TitanVertex> dups = Lambdas.get(() -> {
        final Map<String, Set<Object>> dedup_query_builder = keys.stream()
                .flatMap(j -> Optionals.streamOf(j.fields(), false))
                .collect(Collectors.groupingBy(kv -> kv.getKey(),
                        Collectors.mapping(kv -> jsonNodeToObject(kv.getValue()), Collectors.toSet())));
        ;

        //TODO (ALEPH-15): would be nice to support custom "fuzzier" queries, since we're doing a dedup stage to pick the actual winning vertices anyway
        // that way you could say query on tokenized-version of name and get anyone with the same first or last name (say) and then pick the most likely
        // one based on the graph ... of course you'd probably want the full graph for that, so it might end up being better served as a "self-analytic" to do is part
        // of post processing?
        // (NOTE: same remarks apply for edges)
        // (NOTE: currently I've been going in the opposite direction, ie enforcing only one vertex per keyset per bucket ... otherwise it's going to get really 
        //  confusing when you try to merge all the different versions that Titan creates because of the lack of an upsert function....)

        final TitanGraphQuery<?> matching_nodes_query = dedup_query_builder.entrySet().stream().reduce(
                tx.query(), (query, kv) -> query.has(kv.getKey(), Contain.IN, kv.getValue()),
                (query1, query2) -> query1 // (can't occur since reduce not parallel)
        );

        return Optionals.streamOf(matching_nodes_query.vertices(), false);
    });

    // Remove false positives, un-authorized nodes, and group by key

    final Map<JsonNode, List<Vertex>> grouped_vertices = dups
            .map(vertex -> Tuples._2T((Vertex) vertex, getElementProperties(vertex, key_fields)))
            .filter(vertex_key -> keys.contains(vertex_key._2())) // (remove false positives)
            .filter(vertex_key -> vertex_filter.test(vertex_key._1())) // (remove un-authorized nodes)
            .collect(Collectors.groupingBy(t2 -> (JsonNode) t2._2(), // (group by key)
                    Collectors.mapping(t2 -> t2._1(), Collectors.toList())));

    return grouped_vertices;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.provider.KubernetesV2ClusterProvider.java

private Set<KubernetesV2Cluster> translateClusters(Collection<CacheData> clusterData) {
    return clusterData.stream().map(this::translateCluster).filter(Objects::nonNull)
            .collect(Collectors.toSet());
}

From source file:com.khartec.waltz.data.entity_alias.EntityAliasDao.java

public int[] updateAliases(EntityReference ref, Collection<String> aliases) {

    LOG.info("Updating aliases for entity: {}, aliases: {}", ref, aliases);

    dsl.delete(ENTITY_ALIAS).where(constrainByEntityReference(ref)).execute();

    List<EntityAliasRecord> records = aliases.stream()
            .map(t -> new EntityAliasRecord(ref.id(), t, ref.kind().name())).collect(Collectors.toList());

    return dsl.batchInsert(records).execute();
}

From source file:com.yahoo.elide.jsonapi.models.Relationship.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*from ww  w  .  ja va 2 s  .  c o m*/

    if (o == null || getClass() != o.getClass()) {
        return false;
    }

    Data<Resource> that = ((Relationship) o).getData();

    if (that == null || data == null) {
        return that == data;
    }

    Collection<ResourceIdentifier> resourceIdentifiers = data.toResourceIdentifiers();
    Collection<ResourceIdentifier> theirIdentifiers = that.toResourceIdentifiers();

    return resourceIdentifiers.stream().allMatch(theirIdentifiers::contains);
}

From source file:com.paytmlabs.hazelcast.mapstore.HazelcastMapStore.java

@Override
public Map<K, V> loadAll(final Collection<K> keys) {
    log.info("Loading All");
    final Map<K, V> map = new HashMap<>();
    dao.findAll(//
            keys.stream()//
                    .map(it -> keyToJson(it))//
                    .collect(Collectors.toList())//
    ).stream().forEach((entry) -> {//ww  w .  j  a v  a 2  s .  c o  m
        map.put(keyFromJson(entry.getId()), valueFromJson(entry.getMessage()));
    });

    return map;
}

From source file:com.spotify.heroic.cluster.NodeRegistry.java

private List<ClusterNode> pickN(final Collection<ClusterNode> options, OptionalLimit n) {
    if (options.isEmpty()) {
        return ImmutableList.of();
    }//from   w ww. java2 s  . co m

    final List<ClusterNode> entries = options.stream().filter(ClusterNode::isAlive)
            .collect(Collectors.toList());

    Collections.shuffle(entries, random);

    return n.limitList(entries);
}

From source file:com.linecorp.armeria.server.docs.Specification.java

private Specification(Collection<ServiceInfo> services, Collection<ClassInfo> classes) {
    final Map<String, ServiceInfo> serviceMap = new TreeMap<>();
    final Map<String, ClassInfo> classMap = new TreeMap<>();

    services.stream().forEach(s -> serviceMap.put(s.name(), s));
    classes.stream().forEach(c -> classMap.put(c.name(), c));

    this.services = Collections.unmodifiableMap(serviceMap);
    this.classes = Collections.unmodifiableMap(classMap);
}