本文整理了Java中java.util.HashSet.<init>()
方法的一些代码示例,展示了HashSet.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashSet.<init>()
方法的具体详情如下:
包路径:java.util.HashSet
类名称:HashSet
方法名:<init>
[英]Constructs a new empty instance of HashSet.
[中]构造HashSet的新空实例。
代码示例来源:origin: spring-projects/spring-framework
public void registerExternallyManagedDestroyMethod(String destroyMethod) {
synchronized (this.postProcessingLock) {
if (this.externallyManagedDestroyMethods == null) {
this.externallyManagedDestroyMethods = new HashSet<>(1);
}
this.externallyManagedDestroyMethods.add(destroyMethod);
}
}
代码示例来源:origin: prestodb/presto
public static <T> HashSet<T> arrayToSet(T[] elements)
{
if (elements != null) {
int len = elements.length;
HashSet<T> result = new HashSet<T>(len);
for (int i = 0; i < len; ++i) {
result.add(elements[i]);
}
return result;
}
return new HashSet<T>();
}
代码示例来源:origin: stackoverflow.com
Set<String> set = new HashSet<String>();
//populate set
for (String s : set) {
System.out.println(s);
}
代码示例来源:origin: sohutv/cachecloud
@Override
public Set<byte[]> keySet() {
Set<byte[]> keySet = new HashSet<byte[]>();
Iterator<ByteArrayWrapper> iterator = internalMap.keySet().iterator();
while (iterator.hasNext()) {
keySet.add(iterator.next().data);
}
return keySet;
}
代码示例来源:origin: apache/incubator-druid
public static Set<String> findDuplicates(Iterable<String> fieldNames)
{
Set<String> duplicates = new HashSet<>();
Set<String> uniqueNames = new HashSet<>();
for (String fieldName : fieldNames) {
String next = StringUtils.toLowerCase(fieldName);
if (uniqueNames.contains(next)) {
duplicates.add(next);
}
uniqueNames.add(next);
}
return duplicates;
}
代码示例来源:origin: apache/storm
@Override
public Collection<Node> takeNodes(int nodesNeeded) {
HashSet<Node> ret = new HashSet<>();
Iterator<Node> it = _nodes.iterator();
while (it.hasNext() && nodesNeeded > ret.size()) {
Node n = it.next();
ret.add(n);
_totalSlots -= n.totalSlotsFree();
it.remove();
}
return ret;
}
代码示例来源:origin: stackoverflow.com
Set<Integer> mySet = new HashSet<Integer>();
mySet.add(1);
mySet.add(2);
mySet.add(3);
for (Set<Integer> s : SetUtils.powerSet(mySet)) {
System.out.println(s);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void asyncResultWithSeparateCallbacksAndValue() throws Exception {
String value = "val";
final Set<String> values = new HashSet<>(1);
ListenableFuture<String> future = AsyncResult.forValue(value);
future.addCallback(values::add, (ex) -> fail("Failure callback not expected: " + ex));
assertSame(value, values.iterator().next());
assertSame(value, future.get());
assertSame(value, future.completable().get());
future.completable().thenAccept(v -> assertSame(value, v));
}
代码示例来源:origin: apache/storm
private static Set<WorkerSlot> newlyAddedSlots(Assignment old, Assignment current) {
Set<NodeInfo> oldSlots = new HashSet<>(old.get_executor_node_port().values());
Set<NodeInfo> niRet = new HashSet<>(current.get_executor_node_port().values());
niRet.removeAll(oldSlots);
Set<WorkerSlot> ret = new HashSet<>();
for (NodeInfo ni : niRet) {
ret.add(new WorkerSlot(ni.get_node(), ni.get_port_iterator().next()));
}
return ret;
}
代码示例来源:origin: swagger-api/swagger-core
private static List<Parameter> collectParameters(Type type, List<Annotation> annotations, Components components, javax.ws.rs.Consumes classConsumes, JsonView jsonViewAnnotation) {
final Iterator<OpenAPIExtension> chain = OpenAPIExtensions.chain();
return chain.hasNext() ? chain.next().extractParameters(annotations, type, new HashSet<>(), components, classConsumes, null, false, jsonViewAnnotation, chain).parameters :
Collections.emptyList();
}
代码示例来源:origin: stackoverflow.com
Set<String> users = new HashSet<>(Arrays.asList("Alice", "Bob"));
System.out.println(users.contains("Alice"));
// -> prints true
System.out.println(users.contains("Jack"));
// -> prints false
代码示例来源:origin: google/guava
private static Set<Feature<?>> computeEntrySetFeatures(Set<Feature<?>> features) {
Set<Feature<?>> derivedFeatures = new HashSet<>();
derivedFeatures.addAll(features);
derivedFeatures.remove(CollectionFeature.GENERAL_PURPOSE);
derivedFeatures.remove(CollectionFeature.SUPPORTS_ADD);
derivedFeatures.remove(CollectionFeature.ALLOWS_NULL_VALUES);
derivedFeatures.add(CollectionFeature.REJECTS_DUPLICATES_AT_CREATION);
if (!derivedFeatures.remove(CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS)) {
derivedFeatures.remove(CollectionFeature.SERIALIZABLE);
}
return derivedFeatures;
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected int act(List<Run<?, ?>> builds) throws IOException {
job.checkPermission(Run.DELETE);
final HashSet<Integer> hsBuilds = new HashSet<>();
for (Run<?, ?> build : builds) {
if (!hsBuilds.contains(build.number)) {
build.delete();
hsBuilds.add(build.number);
}
}
stdout.println("Deleted "+hsBuilds.size()+" builds");
return 0;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFlatMapSelectorMaxConcurrent() {
final int m = 4;
final AtomicInteger subscriptionCount = new AtomicInteger();
Observable<Integer> source = Observable.range(1, 10)
.flatMap(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return composer(Observable.range(t1 * 10, 2), subscriptionCount, m)
.subscribeOn(Schedulers.computation());
}
}, new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer t1, Integer t2) {
return t1 * 1000 + t2;
}
}, m);
TestObserver<Integer> to = new TestObserver<Integer>();
source.subscribe(to);
to.awaitTerminalEvent();
to.assertNoErrors();
Set<Integer> expected = new HashSet<Integer>(Arrays.asList(
1010, 1011, 2020, 2021, 3030, 3031, 4040, 4041, 5050, 5051,
6060, 6061, 7070, 7071, 8080, 8081, 9090, 9091, 10100, 10101
));
Assert.assertEquals(expected.size(), to.valueCount());
System.out.println("--> testFlatMapSelectorMaxConcurrent: " + to.values());
Assert.assertTrue(expected.containsAll(to.values()));
}
代码示例来源:origin: jenkinsci/jenkins
private Set<UpdateSite.Warning> getActiveWarnings() {
UpdateSiteWarningsConfiguration configuration = ExtensionList.lookupSingleton(UpdateSiteWarningsConfiguration.class);
HashSet<UpdateSite.Warning> activeWarnings = new HashSet<>();
for (UpdateSite.Warning warning : configuration.getApplicableWarnings()) {
if (!configuration.getIgnoredWarnings().contains(warning.id)) {
activeWarnings.add(warning);
}
}
return Collections.unmodifiableSet(activeWarnings);
}
代码示例来源:origin: apache/rocketmq
public Set<String> whichGroupByTopic(final String topic) {
Set<String> groups = new HashSet<String>();
Iterator<Entry<String, ConcurrentMap<Integer, Long>>> it = this.offsetTable.entrySet().iterator();
while (it.hasNext()) {
Entry<String, ConcurrentMap<Integer, Long>> next = it.next();
String topicAtGroup = next.getKey();
String[] arrays = topicAtGroup.split(TOPIC_GROUP_SEPARATOR);
if (arrays.length == 2) {
if (topic.equals(arrays[0])) {
groups.add(arrays[1]);
}
}
}
return groups;
}
代码示例来源:origin: spring-projects/spring-framework
private boolean isDependent(String beanName, String dependentBeanName, @Nullable Set<String> alreadySeen) {
if (alreadySeen != null && alreadySeen.contains(beanName)) {
return false;
}
String canonicalName = canonicalName(beanName);
Set<String> dependentBeans = this.dependentBeanMap.get(canonicalName);
if (dependentBeans == null) {
return false;
}
if (dependentBeans.contains(dependentBeanName)) {
return true;
}
for (String transitiveDependency : dependentBeans) {
if (alreadySeen == null) {
alreadySeen = new HashSet<>();
}
alreadySeen.add(beanName);
if (isDependent(transitiveDependency, dependentBeanName, alreadySeen)) {
return true;
}
}
return false;
}
代码示例来源:origin: apache/rocketmq
public HashSet<String> queryTopicConsumeByWho(final String topic) {
HashSet<String> groups = new HashSet<>();
Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
while (it.hasNext()) {
Entry<String, ConsumerGroupInfo> entry = it.next();
ConcurrentMap<String, SubscriptionData> subscriptionTable =
entry.getValue().getSubscriptionTable();
if (subscriptionTable.containsKey(topic)) {
groups.add(entry.getKey());
}
}
return groups;
}
}
代码示例来源:origin: google/guava
@Override
public Set<V> removeAll(Object key) {
Set<V> values = new HashSet<V>(2);
if (!map.containsKey(key)) {
return values;
}
values.add(map.remove(key));
return values;
}
代码示例来源:origin: stackoverflow.com
Map<String, String> map = new HashMap<>();
map.put("a", "");
map.put("b", "");
map.put("c", "");
Set<String> set = new HashSet<> ();
set.add("a");
set.add("b");
map.keySet().removeAll(set);
System.out.println(map); //only contains "c"
内容来源于网络,如有侵权,请联系作者删除!