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

x33g5p2x  于2022-01-17 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(438)

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

Collectors.toSet介绍

暂无

代码示例

代码示例来源: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: spring-projects/spring-framework

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

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

private static <T> Set<T> union(Set<T> set1, Set<T> set2)
{
  return Stream.concat(set1.stream(), set2.stream())
      .collect(toSet());
}

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

@Override
public List<Symbol> getOutputSymbols()
{
  return ImmutableList.<Symbol>builder()
      .addAll(groupingSets.stream()
          .flatMap(Collection::stream)
          .collect(toSet()))
      .addAll(aggregationArguments)
      .add(groupIdSymbol)
      .build();
}

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

private static Set<HttpMethod> initAllowedHttpMethods(Set<HttpMethod> declaredMethods) {
  if (declaredMethods.isEmpty()) {
    return EnumSet.allOf(HttpMethod.class).stream()
        .filter(method -> method != HttpMethod.TRACE)
        .collect(Collectors.toSet());
  }
  else {
    Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods);
    if (result.contains(HttpMethod.GET)) {
      result.add(HttpMethod.HEAD);
    }
    result.add(HttpMethod.OPTIONS);
    return result;
  }
}

代码示例来源:origin: neo4j/neo4j

static int countUniqueValues( Object[] updates )
{
  return Stream.of( updates ).collect( Collectors.toSet() ).size();
}

代码示例来源:origin: SonarSource/sonarqube

static Set<Metric> extractMetrics(List<IssueMetricFormula> formulas) {
  return formulas.stream()
   .flatMap(f -> Stream.concat(Stream.of(f.getMetric()), f.getDependentMetrics().stream()))
   .collect(Collectors.toSet());
 }
}

代码示例来源: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: spring-projects/spring-framework

private Set<String> names(Class<?>... classes) {
  return stream(classes).map(Class::getName).collect(toSet());
}

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

private static void verifyBroadcastPartitioning(List<Tuple2<Integer, String>> broadcastPartitionResult) {
  final Set<Tuple2<Integer, String>> expectedResult = INPUT.stream().flatMap(
    input -> IntStream.range(0, PARALLELISM).mapToObj(
      i -> Tuple2.of(i, input)))
    .collect(Collectors.toSet());
  assertEquals(
    expectedResult,
    new HashSet<>(broadcastPartitionResult));
}

代码示例来源:origin: dropwizard/dropwizard

private static Set<Field> findAnnotatedFields(Class<?> testClass, boolean isStaticMember) {
  final Set<Field> set = Arrays.stream(testClass.getDeclaredFields()).
    filter(m -> isStaticMember == Modifier.isStatic(m.getModifiers())).
    filter(m -> DropwizardExtension.class.isAssignableFrom(m.getType())).
    collect(Collectors.toSet());
  if (!testClass.getSuperclass().equals(Object.class)) {
    set.addAll(findAnnotatedFields(testClass.getSuperclass(), isStaticMember));
  }
  return set;
}

代码示例来源:origin: neo4j/neo4j

@Override
public Capability[] capabilities()
{
  Set<Capability> myCapabilities = Stream.of( actual.capabilities() ).collect( toSet() );
  myCapabilities.add( Capability.SECONDARY_RECORD_UNITS );
  return myCapabilities.toArray( new Capability[0] );
}

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

private static <T> Set<T> union(Set<T> set1, Set<T> set2)
{
  return Stream.concat(set1.stream(), set2.stream())
      .collect(toSet());
}

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

@Override
public Set<Entry<String, List<String>>> entrySet() {
  return Collections.unmodifiableSet(this.headers.entrySet().stream()
      .map(AbstractMap.SimpleImmutableEntry::new)
      .collect(Collectors.toSet()));
}

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

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

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

private Set<TaskLock> getAllLocks(List<Task> tasks)
{
 return tasks.stream()
       .flatMap(task -> taskStorage.getLocks(task.getId()).stream())
       .collect(Collectors.toSet());
}

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

public Set<String> getAllTables(String schema)
    throws SchemaNotFoundException
{
  ImmutableSet.Builder<String> builder = ImmutableSet.builder();
  builder.addAll(ImmutableList.copyOf(client.getDatabase(schema).listCollectionNames()).stream()
      .filter(name -> !name.equals(schemaCollection))
      .filter(name -> !SYSTEM_TABLES.contains(name))
      .collect(toSet()));
  builder.addAll(getTableMetadataNames(schema));
  return builder.build();
}

代码示例来源:origin: confluentinc/ksql

private void givenTopicsExistInKafka(final String... topicNames) {
  when(kafkaTopicClient.listTopicNames())
    .thenReturn(Stream.of(topicNames).collect(Collectors.toSet()));
 }
}

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

private static <T> Set<T> intersect(Set<T> set1, Set<T> set2)
{
  return set1.stream()
      .filter(set2::contains)
      .collect(toSet());
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void selectByKeys_throws_IAE_when_keys_contains_empty_string() {
 Random random = new Random();
 Set<String> keysIncludingAnEmptyString = Stream.of(
  IntStream.range(0, random.nextInt(10)).mapToObj(i -> "b_" + i),
  Stream.of(""),
  IntStream.range(0, random.nextInt(10)).mapToObj(i -> "a_" + i))
  .flatMap(s -> s)
  .collect(Collectors.toSet());
 expectKeyNullOrEmptyIAE();
 underTest.selectByKeys(dbSession, keysIncludingAnEmptyString);
}

相关文章