Set<String> set = new HashSet<String>(); //populate set for (String s : set) { System.out.println(s); }
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; }
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); }
@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)); }
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; }
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(); }
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; }
@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; }
@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())); }
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); }
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; }
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; }
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; } }