java.util.Collection.stream()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(172)

本文整理了Java中java.util.Collection.stream()方法的一些代码示例,展示了Collection.stream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collection.stream()方法的具体详情如下:
包路径:java.util.Collection
类名称:Collection
方法名:stream

Collection.stream介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

  1. public static <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
  2. return map.entrySet()
  3. .stream()
  4. .filter(entry -> Objects.equals(entry.getValue(), value))
  5. .map(Map.Entry::getKey)
  6. .collect(Collectors.toSet());
  7. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public Collection<List<String>> values() {
  3. return this.headers.getHeaderNames().stream()
  4. .map(this.headers::get)
  5. .collect(Collectors.toList());
  6. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public Set<String> keySet() {
  3. return this.headers.getHeaderNames().stream()
  4. .map(HttpString::toString)
  5. .collect(Collectors.toSet());
  6. }

代码示例来源:origin: apache/incubator-druid

  1. @JsonCreator
  2. public AffinityConfig(
  3. @JsonProperty("affinity") Map<String, Set<String>> affinity,
  4. @JsonProperty("strong") boolean strong
  5. )
  6. {
  7. this.affinity = affinity;
  8. this.strong = strong;
  9. this.affinityWorkers = affinity.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
  10. }

代码示例来源:origin: prestodb/presto

  1. private ComputedStatistics(
  2. List<String> groupingColumns,
  3. List<Block> groupingValues,
  4. Map<TableStatisticType, Block> tableStatistics,
  5. Map<ColumnStatisticMetadata, Block> columnStatistics)
  6. {
  7. this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
  8. this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
  9. if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
  10. throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
  11. }
  12. this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
  13. if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
  14. throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
  15. }
  16. this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
  17. if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
  18. throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
  19. }
  20. }

代码示例来源:origin: prestodb/presto

  1. private static <T> List<T> removeAll(Collection<T> collection, Collection<T> elementsToRemove)
  2. {
  3. return collection.stream()
  4. .filter(element -> !elementsToRemove.contains(element))
  5. .collect(toImmutableList());
  6. }
  7. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public boolean containsValue(Object value) {
  3. return (value instanceof String &&
  4. this.headers.getHeaderNames().stream()
  5. .map(this.headers::get)
  6. .anyMatch(values -> values.contains(value)));
  7. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. @Override
  2. public void values(Handler<AsyncResult<List<V>>> asyncResultHandler) {
  3. List<V> result = map.values().stream()
  4. .filter(Holder::hasNotExpired)
  5. .map(h -> h.value)
  6. .collect(toList());
  7. asyncResultHandler.handle(Future.succeededFuture(result));
  8. }

代码示例来源:origin: prestodb/presto

  1. public List<RemoteTask> getAllTasks()
  2. {
  3. return tasks.values().stream()
  4. .flatMap(Set::stream)
  5. .collect(toImmutableList());
  6. }

代码示例来源:origin: prestodb/presto

  1. private ComputedStatistics(
  2. List<String> groupingColumns,
  3. List<Block> groupingValues,
  4. Map<TableStatisticType, Block> tableStatistics,
  5. Map<ColumnStatisticMetadata, Block> columnStatistics)
  6. {
  7. this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
  8. this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
  9. if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
  10. throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
  11. }
  12. this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
  13. if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
  14. throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
  15. }
  16. this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
  17. if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
  18. throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
  19. }
  20. }

代码示例来源:origin: prestodb/presto

  1. public static ResettableRandomizedIterator<Node> randomizedNodes(NodeMap nodeMap, boolean includeCoordinator, Set<Node> excludedNodes)
  2. {
  3. ImmutableList<Node> nodes = nodeMap.getNodesByHostAndPort().values().stream()
  4. .filter(node -> includeCoordinator || !nodeMap.getCoordinatorNodeIds().contains(node.getNodeIdentifier()))
  5. .filter(node -> !excludedNodes.contains(node))
  6. .collect(toImmutableList());
  7. return new ResettableRandomizedIterator<>(nodes);
  8. }

代码示例来源:origin: apache/kafka

  1. private Set<String> topics() {
  2. return updateResponse.topicMetadata().stream()
  3. .map(MetadataResponse.TopicMetadata::topic)
  4. .collect(Collectors.toSet());
  5. }
  6. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. protected void applyCookies() {
  3. getCookies().values().stream().flatMap(Collection::stream)
  4. .map(cookie -> new DefaultCookie(cookie.getName(), cookie.getValue()))
  5. .forEach(this.request::addCookie);
  6. }

代码示例来源:origin: apache/incubator-druid

  1. @Override
  2. public Collection<ImmutableDruidDataSource> getDataSources()
  3. {
  4. return dataSources.values()
  5. .stream()
  6. .map(DruidDataSource::toImmutableDruidDataSource)
  7. .collect(Collectors.toList());
  8. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public Result apply(AggregationNode aggregationNode, Captures captures, Context context)
  3. {
  4. Set<Symbol> requiredInputs = Streams.concat(
  5. aggregationNode.getGroupingKeys().stream(),
  6. aggregationNode.getHashSymbol().map(Stream::of).orElse(Stream.empty()),
  7. aggregationNode.getAggregations().values().stream()
  8. .flatMap(PruneAggregationSourceColumns::getAggregationInputs))
  9. .collect(toImmutableSet());
  10. return restrictChildOutputs(context.getIdAllocator(), aggregationNode, requiredInputs)
  11. .map(Result::ofPlanNode)
  12. .orElse(Result.empty());
  13. }

代码示例来源:origin: prestodb/presto

  1. /**
  2. * Enforce memory limits at the query level
  3. */
  4. private void enforceMemoryLimits()
  5. {
  6. List<QueryExecution> runningQueries = queryTracker.getAllQueries().stream()
  7. .filter(query -> query.getState() == RUNNING)
  8. .collect(toImmutableList());
  9. memoryManager.process(runningQueries, this::getQueries);
  10. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. protected void applyCookies() {
  3. getCookies().values().stream().flatMap(Collection::stream)
  4. .map(cookie -> new HttpCookie(cookie.getName(), cookie.getValue()))
  5. .forEach(this.jettyRequest::cookie);
  6. }

代码示例来源:origin: apache/incubator-druid

  1. public Collection<ContainerClass> getInventory()
  2. {
  3. return containers.values()
  4. .stream()
  5. .map(ContainerHolder::getContainer)
  6. .collect(Collectors.toList());
  7. }

代码示例来源:origin: prestodb/presto

  1. private void createPageProducers(int numMergeSources)
  2. {
  3. AtomicInteger counter = new AtomicInteger(0);
  4. splitPages = pages.stream()
  5. .collect(Collectors.groupingBy(it -> counter.getAndIncrement() % numMergeSources))
  6. .values().stream()
  7. .collect(toImmutableList());
  8. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. public synchronized List<T> handlers() {
  2. return handlerMap.values().stream()
  3. .flatMap(handlers -> handlers.list.stream())
  4. .map(holder -> holder.handler)
  5. .collect(Collectors.toList());
  6. }

相关文章