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

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

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

HashSet.stream介绍

暂无

代码示例

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

public static List<String> topicsListsMinus(List<String> list1, List<String> list2) {
  HashSet<String> s1 = new HashSet<>(list1);
  s1.removeAll(list2);
  return s1.stream().collect(Collectors.toList());
}

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

private Set<E> getDiff(Set<? extends E> set1, Set<? extends E> set2) {
    HashSet<E> hashSet = new HashSet<>();
    hashSet.addAll(set1);
    hashSet.addAll(set2);
    return hashSet.stream().filter(new Predicate<E>() {
      @Override
      public boolean test(E e) {
        return set1.contains(e) && !set2.contains(e);
      }
    }).collect(Collectors.toSet());
  }
};

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

private Set<E> getDiff(Set<? extends E> set1, Set<? extends E> set2) {
    HashSet<E> hashSet = new HashSet<>();
    hashSet.addAll(set1);
    hashSet.addAll(set2);
    return hashSet.stream().filter(new Predicate<E>() {
      @Override
      public boolean test(E e) {
        return set1.contains(e) && !set2.contains(e);
      }
    }).collect(Collectors.toSet());
  }
};

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

private static List<String> sanitizeScmAccounts(@Nullable List<String> scmAccounts) {
 if (scmAccounts != null) {
  return new HashSet<>(scmAccounts).stream()
   .map(Strings::emptyToNull)
   .filter(Objects::nonNull)
   .sorted(String::compareToIgnoreCase)
   .collect(toList(scmAccounts.size()));
 }
 return Collections.emptyList();
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
@Deprecated
public Set<OfflinePlayer> getPlayers() throws IllegalStateException {
  Set<OfflinePlayer> playerObjectSet = new HashSet<>(players.size());
  playerObjectSet.addAll(
    players.stream().map(Bukkit::getOfflinePlayer).collect(Collectors.toList()));
  return playerObjectSet;
}

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

private void warnAboutDeprecatedConnectors( @Nonnull Map<String,String> connectorSettings,
    @Nonnull Consumer<String> warningConsumer )
{
  final HashSet<String> nonDefaultConnectors = new HashSet<>();
  connectorSettings.entrySet().stream()
      .map( Entry::getKey )
      .filter( settingKey ->
      {
        String name = settingKey.split( "\\." )[2];
        return isDeprecatedConnectorName( name );
      } )
      .forEach( nonDefaultConnectors::add );
  if ( !nonDefaultConnectors.isEmpty() )
  {
    warningConsumer.accept( format(
        DEPRECATED_CONNECTOR_MSG,
        nonDefaultConnectors.stream()
            .sorted()
            .map( s -> format( ">  %s%n", s ) )
            .collect( joining() ) ) );
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
  Set<Material> materials = transparent.stream().map(Material::getMaterial)
      .collect(Collectors.toSet());
  return getLineOfSight(materials, maxDistance, maxLength);
}

代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises

@GenerateMicroBenchmark
public int serialHashSet() {
  return hashSet.stream().mapToInt(i -> i).sum();
}

代码示例来源:origin: hs-web/hsweb-framework

protected void trySyncUserRole(final String userId, final List<String> roleIdList) {
  new HashSet<>(roleIdList).stream()
      .map(roleId -> {
        UserRoleEntity roleEntity = entityFactory.newInstance(UserRoleEntity.class);
        roleEntity.setRoleId(roleId);
        roleEntity.setUserId(userId);
        return roleEntity;
      })
      .forEach(userRoleDao::insert);
}

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

public List<URL> getListeners() {
 return Arrays.stream(server.getConnectors())
   .filter(connector -> connector instanceof ServerConnector)
   .map(ServerConnector.class::cast)
   .map(connector -> {
    try {
     final String protocol = new HashSet<>(connector.getProtocols())
       .stream()
       .map(String::toLowerCase)
       .anyMatch(s -> s.equals("ssl")) ? "https" : "http";
     final int localPort = connector.getLocalPort();
     return new URL(protocol, "localhost", localPort, "");
    } catch (final Exception e) {
     throw new RuntimeException("Malformed listener", e);
    }
   })
   .collect(Collectors.toList());
}

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

int foo(int y) {
  MathOperation case1 = (x) -> x + x;
  MathOperation case2 = (x) -> { return x + x; };
  MathOperation case3 = (int x) -> x + x;
  MathOperation case4 = x -> x + x;
  MathOperation2 case5 = (a, b) -> a + b;
  MathOperation2 case6 = (int a, int b) -> a + b;
  MathOperation2 case7 = (int a, int b) -> { return a + b; };
  Objects.requireNonNull(null, () -> "message");
  call((x) -> x + x);
  new HashSet<Integer>().stream().filter((filter) -> filter > 0);
  return y;
}

代码示例来源:origin: stanfordnlp/CoreNLP

new HashSet<>(props.keySet()).stream().filter(key -> !key.toString().startsWith("openie.")).forEach(key -> props.setProperty("openie." + key.toString(), props.getProperty(key.toString())));

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

e.getValue().setLocation("<html>" + locs.stream().collect(Collectors.joining("<br>")) + "</html>");

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

new HashSet<>(properties).stream()
  .filter(prop -> UNDOCUMENTED_PROPERTIES.contains(clss.getSimpleName() + "." + prop))
  .forEach(properties::remove);

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

/**
 * Returns a list whose elements are instances of all the {@link GremlinScriptEngineFactory} classes
 * found by the discovery mechanism.
 *
 * @return List of all discovered {@link GremlinScriptEngineFactory} objects.
 */
@Override
public List<GremlinScriptEngineFactory> getEngineFactories() {
  final List<GremlinScriptEngineFactory> res = new ArrayList<>(engineSpis.size());
  res.addAll(engineSpis.stream().collect(Collectors.toList()));
  return Collections.unmodifiableList(res);
}

代码示例来源:origin: ahmetaa/zemberek-nlp

/**
 * Generates a new LmVocabulary instance that contains words that exist in both `v1` and `v2`
 * There is no guarantee that new vocabulary indexes will match with v1 or v2.
 */
public static LmVocabulary intersect(LmVocabulary v1, LmVocabulary v2) {
 HashSet<String> ls = new HashSet<>(v1.vocabulary);
 List<String> intersection = new ArrayList<>(Math.min(v1.size(), v2.size()));
 intersection.addAll(new HashSet<>(v2.vocabulary)
   .stream()
   .filter(ls::contains)
   .collect(Collectors.toList()));
 return new LmVocabulary(intersection);
}

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

@Override
public void addSummarizers(String tableName, SummarizerConfiguration... newConfigs)
  throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
 HashSet<SummarizerConfiguration> currentConfigs = new HashSet<>(
   SummarizerConfiguration.fromTableProperties(getProperties(tableName)));
 HashSet<SummarizerConfiguration> newConfigSet = new HashSet<>(Arrays.asList(newConfigs));
 newConfigSet.removeIf(currentConfigs::contains);
 Set<String> newIds = newConfigSet.stream().map(SummarizerConfiguration::getPropertyId)
   .collect(toSet());
 for (SummarizerConfiguration csc : currentConfigs) {
  if (newIds.contains(csc.getPropertyId())) {
   throw new IllegalArgumentException("Summarizer property id is in use by " + csc);
  }
 }
 Set<Entry<String,String>> es = SummarizerConfiguration.toTableProperties(newConfigSet)
   .entrySet();
 for (Entry<String,String> entry : es) {
  setProperty(tableName, entry.getKey(), entry.getValue());
 }
}

代码示例来源:origin: rakam-io/rakam

missingPartitions = new HashSet<>();
String values = set.stream().map(item -> format("('%s')", item)).collect(Collectors.joining(", "));
ResultSet resultSet = statement.executeQuery(format("select part from (VALUES%s) data (part) where part not in (\n" +
    "\tselect substring(cchild.relname, %d)  from pg_catalog.pg_class c \n" +

代码示例来源:origin: org.glassfish.jersey.core/jersey-common

private Set<E> getDiff(Set<? extends E> set1, Set<? extends E> set2) {
    HashSet<E> hashSet = new HashSet<>();
    hashSet.addAll(set1);
    hashSet.addAll(set2);
    return hashSet.stream().filter(new Predicate<E>() {
      @Override
      public boolean test(E e) {
        return set1.contains(e) && !set2.contains(e);
      }
    }).collect(Collectors.toSet());
  }
};

代码示例来源:origin: usethesource/capsule

@Property(trials = DEFAULT_TRIALS)
public void containsAfterInsert(@Size(min = 0, max = 0) final CT emptySet,
  @Size(min = 1, max = MAX_SIZE) final java.util.HashSet<T> inputValues) {
 CT testSet = emptySet;
 for (T newValue : inputValues) {
  final CT tmpSet = (CT) testSet.__insert(newValue);
  testSet = tmpSet;
 }
 boolean containsInsertedValues = inputValues.stream().allMatch(testSet::contains);
 assertTrue("Must contain all inserted values.", containsInsertedValues);
}

相关文章