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

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

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

Collection.stream介绍

暂无

代码示例

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

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

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

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

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

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

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

@JsonCreator
public AffinityConfig(
  @JsonProperty("affinity") Map<String, Set<String>> affinity,
  @JsonProperty("strong") boolean strong
)
{
 this.affinity = affinity;
 this.strong = strong;
 this.affinityWorkers = affinity.values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
}

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

private ComputedStatistics(
    List<String> groupingColumns,
    List<Block> groupingValues,
    Map<TableStatisticType, Block> tableStatistics,
    Map<ColumnStatisticMetadata, Block> columnStatistics)
{
  this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
  this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
  if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
  }
  this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
  if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
  }
  this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
  if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
  }
}

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

private static <T> List<T> removeAll(Collection<T> collection, Collection<T> elementsToRemove)
  {
    return collection.stream()
        .filter(element -> !elementsToRemove.contains(element))
        .collect(toImmutableList());
  }
}

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

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

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

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

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

public List<RemoteTask> getAllTasks()
{
  return tasks.values().stream()
      .flatMap(Set::stream)
      .collect(toImmutableList());
}

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

private ComputedStatistics(
    List<String> groupingColumns,
    List<Block> groupingValues,
    Map<TableStatisticType, Block> tableStatistics,
    Map<ColumnStatisticMetadata, Block> columnStatistics)
{
  this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
  this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
  if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
  }
  this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
  if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
  }
  this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
  if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
  }
}

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

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

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

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

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

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

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

@Override
public Collection<ImmutableDruidDataSource> getDataSources()
{
 return dataSources.values()
          .stream()
          .map(DruidDataSource::toImmutableDruidDataSource)
          .collect(Collectors.toList());
}

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

@Override
public Result apply(AggregationNode aggregationNode, Captures captures, Context context)
{
  Set<Symbol> requiredInputs = Streams.concat(
      aggregationNode.getGroupingKeys().stream(),
      aggregationNode.getHashSymbol().map(Stream::of).orElse(Stream.empty()),
      aggregationNode.getAggregations().values().stream()
          .flatMap(PruneAggregationSourceColumns::getAggregationInputs))
      .collect(toImmutableSet());
  return restrictChildOutputs(context.getIdAllocator(), aggregationNode, requiredInputs)
      .map(Result::ofPlanNode)
      .orElse(Result.empty());
}

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

/**
 * Enforce memory limits at the query level
 */
private void enforceMemoryLimits()
{
  List<QueryExecution> runningQueries = queryTracker.getAllQueries().stream()
      .filter(query -> query.getState() == RUNNING)
      .collect(toImmutableList());
  memoryManager.process(runningQueries, this::getQueries);
}

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

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

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

public Collection<ContainerClass> getInventory()
{
 return containers.values()
          .stream()
          .map(ContainerHolder::getContainer)
          .collect(Collectors.toList());
}

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

private void createPageProducers(int numMergeSources)
{
  AtomicInteger counter = new AtomicInteger(0);
  splitPages = pages.stream()
      .collect(Collectors.groupingBy(it -> counter.getAndIncrement() % numMergeSources))
      .values().stream()
      .collect(toImmutableList());
}

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

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

相关文章