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

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

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

Set.stream介绍

暂无

代码示例

代码示例来源:origin: google/guava

@Override
public Stream<E> stream() {
 return set1.stream().filter(set2::contains);
}

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

protected static Set<String> getSubProperties(Map<String, String> properties, String prefix) {
  return properties.keySet().stream().filter(k -> k.contains(prefix)).map(k -> {
    k = k.substring(prefix.length());
    return k.substring(0, k.indexOf("."));
  }).collect(Collectors.toSet());
}

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

/**
 * Return method model for the given method on consumer side
 *
 * @param method method object
 * @return method model
 */
public ConsumerMethodModel getMethodModel(String method) {
  Optional<Map.Entry<Method, ConsumerMethodModel>> consumerMethodModelEntry = methodModels.entrySet().stream().filter(entry -> entry.getKey().getName().equals(method)).findFirst();
  return consumerMethodModelEntry.map(Map.Entry::getValue).orElse(null);
}

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

private LinkedMultiValueMap<String, Part> toMultiValueMap(Map<String, Collection<Part>> map) {
  return new LinkedMultiValueMap<>(map.entrySet().stream()
      .collect(Collectors.toMap(Map.Entry::getKey, e -> toList(e.getValue()))));
}

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

private String formatHeaders(HttpHeaders headers, String delimiter) {
  return headers.entrySet().stream()
      .map(entry -> entry.getKey() + ": " + entry.getValue())
      .collect(Collectors.joining(delimiter));
}

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

public static int getConsumerAddressNum(String serviceUniqueName) {
    Set<ConsumerInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getConsumerInvoker(serviceUniqueName);
    return providerInvokerWrapperSet.stream()
        .map(w -> w.getRegistryDirectory().getUrlInvokerMap())
        .filter(Objects::nonNull)
        .mapToInt(Map::size).sum();
  }
}

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

/**
 * Return declared "producible" types but only among those that also
 * match the "methods" and "consumes" conditions.
 */
public Set<MediaType> getProducibleMediaTypes() {
  return this.partialMatches.stream().filter(PartialMatch::hasConsumesMatch).
      flatMap(m -> m.getInfo().getProducesCondition().getProducibleMediaTypes().stream()).
      collect(Collectors.toCollection(LinkedHashSet::new));
}

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

public static ActualProperties deriveProperties(PlanNode node, List<ActualProperties> inputProperties, Metadata metadata, Session session, TypeProvider types, SqlParser parser)
{
  ActualProperties output = node.accept(new Visitor(metadata, session, types, parser), inputProperties);
  output.getNodePartitioning().ifPresent(partitioning ->
      verify(node.getOutputSymbols().containsAll(partitioning.getColumns()), "Node-level partitioning properties contain columns not present in node's output"));
  verify(node.getOutputSymbols().containsAll(output.getConstants().keySet()), "Node-level constant properties contain columns not present in node's output");
  Set<Symbol> localPropertyColumns = output.getLocalProperties().stream()
      .flatMap(property -> property.getColumns().stream())
      .collect(Collectors.toSet());
  verify(node.getOutputSymbols().containsAll(localPropertyColumns), "Node-level local properties contain columns not present in node's output");
  return output;
}

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

static Map<String, List<String>> allImports() {
  return TestImportGroup.imports.entrySet()
      .stream()
      .collect(Collectors.toMap((entry) -> entry.getKey().getClassName(),
          Map.Entry::getValue));
}
private final List<Entry> instanceImports = new ArrayList<>();

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

protected static Set<String> getSubProperties(Map<String, String> properties, String prefix) {
  return properties.keySet().stream().filter(k -> k.contains(prefix)).map(k -> {
    k = k.substring(prefix.length());
    return k.substring(0, k.indexOf("."));
  }).collect(Collectors.toSet());
}

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

public Map<String, Double> getOperatorHashCollisionsAverages()
{
  return operatorHashCollisionsStats.entrySet().stream()
      .collect(toMap(
          Map.Entry::getKey,
          entry -> entry.getValue().getWeightedHashCollisions() / operatorInputStats.get(entry.getKey()).getInputPositions()));
}

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

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

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

/**
 * Return method model for the given method on consumer side
 *
 * @param method method object
 * @return method model
 */
public ConsumerMethodModel getMethodModel(String method) {
  Optional<Map.Entry<Method, ConsumerMethodModel>> consumerMethodModelEntry = methodModels.entrySet().stream().filter(entry -> entry.getKey().getName().equals(method)).findFirst();
  return consumerMethodModelEntry.map(Map.Entry::getValue).orElse(null);
}

代码示例来源:origin: google/guava

@Override
public Stream<E> stream() {
 return Stream.concat(set1.stream(), set2.stream().filter(e -> !set1.contains(e)));
}

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

public static int getConsumerAddressNum(String serviceUniqueName) {
    Set<ConsumerInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getConsumerInvoker(serviceUniqueName);
    return providerInvokerWrapperSet.stream()
        .map(w -> w.getRegistryDirectory().getUrlInvokerMap())
        .filter(Objects::nonNull)
        .mapToInt(Map::size).sum();
  }
}

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

/**
 * Return declared "consumable" types but only among those that also
 * match the "methods" condition.
 */
public Set<MediaType> getConsumableMediaTypes() {
  return this.partialMatches.stream().filter(PartialMatch::hasMethodsMatch).
      flatMap(m -> m.getInfo().getConsumesCondition().getConsumableMediaTypes().stream()).
      collect(Collectors.toCollection(LinkedHashSet::new));
}

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

private String formatMappings(Class<?> userType, Map<Method, T> methods) {
  String formattedType = Arrays.stream(ClassUtils.getPackageName(userType).split("\\."))
      .map(p -> p.substring(0, 1))
      .collect(Collectors.joining(".", "", ".")) + userType.getSimpleName();
  Function<Method, String> methodFormatter = method -> Arrays.stream(method.getParameterTypes())
      .map(Class::getSimpleName)
      .collect(Collectors.joining(",", "(", ")"));
  return methods.entrySet().stream()
      .map(e -> {
        Method method = e.getKey();
        return e.getValue() + ": " + method.getName() + methodFormatter.apply(method);
      })
      .collect(Collectors.joining("\n\t", "\n\t" + formattedType + ":" + "\n\t", ""));
}

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

public Map<String, Double> getOperatorInputPositionsAverages()
{
  return operatorInputStats.entrySet().stream()
      .collect(toMap(
          Map.Entry::getKey,
          entry -> (double) entry.getValue().getInputPositions() / operatorInputStats.get(entry.getKey()).getTotalDrivers()));
}

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

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

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

/**
 * Configure path prefixes to apply to controller methods.
 * <p>Prefixes are used to enrich the mappings of every {@code @RequestMapping}
 * method whose controller type is matched by a corresponding
 * {@code Predicate} in the map. The prefix for the first matching predicate
 * is used, assuming the input map has predictable order.
 * <p>Consider using {@link org.springframework.web.method.HandlerTypePredicate
 * HandlerTypePredicate} to group controllers.
 * @param prefixes a map with path prefixes as key
 * @since 5.1
 * @see org.springframework.web.method.HandlerTypePredicate
 */
public void setPathPrefixes(Map<String, Predicate<Class<?>>> prefixes) {
  this.pathPrefixes.clear();
  prefixes.entrySet().stream()
      .filter(entry -> StringUtils.hasText(entry.getKey()))
      .forEach(entry -> this.pathPrefixes.put(entry.getKey(), entry.getValue()));
}

相关文章