Java Code Examples for java.util.Collections#newSetFromMap()
The following examples show how to use
java.util.Collections#newSetFromMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSourcedListFacet.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
/** * Add the given object with the given source to the list of objects stored * in this AbstractSourcedListFacet for the resource represented by the * given PCGenIdentifier * * @param id * The PCGenIdentifier representing the resource for which the * given item should be added * @param obj * The object to be added to the list of objects stored in this * AbstractSourcedListFacet for the resource represented by the * given PCGenIdentifier * @param source * The source for the given object */ public void add(IDT id, T obj, Object source) { Objects.requireNonNull(obj, "Object to add may not be null"); Map<T, Set<Object>> map = getConstructingCachedMap(id); Set<Object> set = map.get(obj); boolean fireNew = (set == null); if (fireNew) { set = Collections.newSetFromMap(new IdentityHashMap<>()); map.put(obj, set); } set.add(source); if (fireNew) { fireDataFacetChangeEvent(id, obj, DataFacetChangeEvent.DATA_ADDED); } }
Example 2
Source File: HeimdallDecorationFilterTest.java From heimdall with Apache License 2.0 | 6 votes |
@Test public void testCallMethodAll() { Map<String, ZuulRoute> routes = new LinkedHashMap<>(); ZuulRoute route = new ZuulRoute("idFoo", "/v2/api/foo", null, "my.dns.com.br", true, null, Collections.newSetFromMap(new ConcurrentHashMap<>())); routes.put("/v2/api/foo", route); Credential opPost = new Credential(HttpMethod.POST.name(), "/api/foo/{id}", "/v2", "apiName", 10L, 88L, 10L, false); Credential opDelete = new Credential(HttpMethod.DELETE.name(), "/api/foo/{id}", "/v2", "apiName", 11L, 88L, 10L, false); Credential opAll = new Credential(HttpMethod.ALL.name(), "/api/foo/{id}", "/v2", "apiName", 12L, 88L, 10L, false); Mockito.when(routeLocator.getAtomicRoutes()).thenReturn(new AtomicReference<>(routes)); Mockito.when(credentialRepository.findByPattern("/v2/api/foo")).thenReturn(Lists.newArrayList(opPost, opDelete, opAll)); HeimdallRoute heimdallRoute = this.filter.getMatchingHeimdallRoute("/v2/api/foo", HttpMethod.GET.name(), this.ctx); assertNotNull(heimdallRoute); assertEquals("/api/foo", heimdallRoute.getRoute().getPath()); }
Example 3
Source File: Jersey2Plugin.java From HotswapAgent with GNU General Public License v2.0 | 6 votes |
/** * Gets a list of classes used in configure the Jersey Application */ private Set<Class<?>> getContainerClasses(Class<?> resourceConfigClass, Object resourceConfig) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method scanClassesMethod = resourceConfigClass.getDeclaredMethod("scanClasses"); scanClassesMethod.setAccessible(true); @SuppressWarnings("unchecked") Set<Class<?>> scannedClasses = (Set<Class<?>>) scanClassesMethod.invoke(resourceConfig); Method getRegisteredClassesMethod = resourceConfigClass.getDeclaredMethod("getRegisteredClasses"); getRegisteredClassesMethod.setAccessible(true); @SuppressWarnings("unchecked") Set<Class<?>> registeredClasses = (Set<Class<?>>)getRegisteredClassesMethod.invoke(resourceConfig); Set<Class<?>> containerClasses = Collections.newSetFromMap(new WeakHashMap<Class<?>, Boolean>()); containerClasses.addAll(scannedClasses); containerClasses.addAll(registeredClasses); return containerClasses; }
Example 4
Source File: KeyGroupPartitionerTestBase.java From flink with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void testPartitionByKeyGroupForSize(int testSize, Random random) throws IOException { final Set<T> allElementsIdentitySet = Collections.newSetFromMap(new IdentityHashMap<>()); final T[] data = generateTestInput(random, testSize, allElementsIdentitySet); Assert.assertEquals(testSize, allElementsIdentitySet.size()); // Test with 5 key-groups. final KeyGroupRange range = new KeyGroupRange(0, 4); final int numberOfKeyGroups = range.getNumberOfKeyGroups(); final ValidatingElementWriterDummy<T> validatingElementWriter = new ValidatingElementWriterDummy<>(keyExtractorFunction, numberOfKeyGroups, allElementsIdentitySet); final KeyGroupPartitioner<T> testInstance = createPartitioner(data, testSize, range, numberOfKeyGroups, validatingElementWriter); final StateSnapshot.StateKeyGroupWriter result = testInstance.partitionByKeyGroup(); for (int keyGroup = 0; keyGroup < numberOfKeyGroups; ++keyGroup) { validatingElementWriter.setCurrentKeyGroup(keyGroup); result.writeStateInKeyGroup(DUMMY_OUT_VIEW, keyGroup); } validatingElementWriter.validateAllElementsSeen(); }
Example 5
Source File: Scheduler.java From Concurnas with MIT License | 6 votes |
private Scheduler(int cnt, String workerNamePrefix, Scheduler parentScheduler) { this.parentScheduler = parentScheduler; masterGroupScheduler = null; children = Collections.newSetFromMap(new WeakHashMap<Scheduler, Boolean>()); dedicatedWorkers = new ConcurrentHashMap<Worker, TerminationState>(); idx = 0; workers = new Worker[cnt]; workerCount = cnt; long wpid = workerPoolId.getAndIncrement(); if (workerNamePrefix == null) { workerNamePrefix = "" + wpid; } for (int n = 0; n < cnt; n++) { // create workers with scheduler allocation offset so as to trick into passing // workload to next holder Worker w = new Worker(new Scheduler(workers, (n + 1) % cnt, dedicatedWorkers, this), String.format("Concurnas Pool Worker-%s-%01d", workerNamePrefix, n), false); workers[n] = w; w.start(); } parentScheduler.registerChildGroupScheduler(this); }
Example 6
Source File: Bug1387.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
public static void test3() { Set<String>[] sets = new Set[10]; for (int i = 0; i < 10; ++i) { sets[i] = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>()); sets[i].add("Foo"); } PoJo p = new PoJo("Foo"); sets[5].remove(p); // <- bug }
Example 7
Source File: CarrierRefresher.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
/** * Creates a new {@link CarrierRefresher}. * * @param environment the environment to use. * @param cluster the cluster reference. */ public CarrierRefresher(final CoreEnvironment environment, final ClusterFacade cluster) { super(environment, cluster); subscriptions = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); this.environment = environment; this.lastPollTimestamps = new ConcurrentHashMap<String, Long>(); this.nodeOffset = 0; this.pollFloorNs = TimeUnit.MILLISECONDS.toNanos(environment.configPollFloorInterval()); long pollInterval = environment.configPollInterval(); if (pollInterval > 0) { LOGGER.debug("Starting polling with interval {}ms", pollInterval); pollerSubscription = Observable .interval(pollInterval, TimeUnit.MILLISECONDS, environment.scheduler()) .subscribe(new Action1<Long>() { @Override public void call(Long aLong) { if (provider() != null) { ClusterConfig config = provider().config(); if (config != null && !config.bucketConfigs().isEmpty()) { refresh(config); } else { LOGGER.debug("No bucket open to refresh, ignoring outdated signal."); } } else { LOGGER.debug("Provider not yet wired up, ignoring outdated signal."); } } }); } else { LOGGER.info("Proactive config polling disabled based on environment setting."); } }
Example 8
Source File: HeimdallDecorationFilterTest.java From heimdall with Apache License 2.0 | 5 votes |
@Test public void matchRouteWithMultiEnvironments() { this.request.setRequestURI("/path/api/foo"); this.request.setMethod(HttpMethod.GET.name()); this.request.addHeader("host", "some-path.com"); Map<String, ZuulRoute> routes = new LinkedHashMap<>(); ZuulRoute route = new ZuulRoute("idFoo", "/path/api/foo", null, "my.dns.com.br", true, null, Collections.newSetFromMap(new ConcurrentHashMap<>())); routes.put("/path/api/foo", route); EnvironmentInfo environmentInfo = new EnvironmentInfo(); environmentInfo.setId(1L); environmentInfo.setOutboundURL("https://some-path.com"); environmentInfo.setVariables(new HashMap<>()); Credential opGet = new Credential(HttpMethod.GET.name(), "/api/foo", "/path", "apiName", 10L, 88L, 10L, false); Credential opDelete = new Credential(HttpMethod.DELETE.name(), "/api/foo", "/path", "apiName", 10L, 88L, 10L, false); Mockito.when(routeLocator.getAtomicRoutes()).thenReturn(new AtomicReference<>(routes)); Mockito.when(credentialRepository.findByPattern("/path/api/foo")).thenReturn(Lists.newArrayList(opGet, opDelete)); Mockito.when(environmentInfoRepository.findByApiIdAndEnvironmentInboundURL(10L, "some-path.com")).thenReturn(environmentInfo); this.filter.run(); assertEquals("/api/foo", this.ctx.get(REQUEST_URI_KEY)); assertTrue(this.ctx.sendZuulResponse()); }
Example 9
Source File: Router.java From arcusplatform with Apache License 2.0 | 5 votes |
public Router() { this.executor = Executors.newCachedThreadPool(new RouterThreadFactory()); this.ports = Collections.newSetFromMap(new ConcurrentHashMap<PortInternal,Boolean>()); this.snoopers = Collections.newSetFromMap(new ConcurrentHashMap<PortInternal,Boolean>()); this.service = new ConcurrentHashMap<>(); this.protocol = new ConcurrentHashMap<>(); }
Example 10
Source File: FileUtils.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("try") public static Collection<File> getPackagePrivateSource(final List<File> compileFiles) { try (TelemetryUtils.ScopedSpan scope = TelemetryUtils.startScopedSpan("FileUtils.getPackagePrivateSource")) { final Set<File> temp = Collections.newSetFromMap(new ConcurrentHashMap<>(8)); compileFiles.parallelStream().forEach(file -> temp.addAll(FileUtils.listJavaFiles(file))); return temp; } }
Example 11
Source File: UndertowRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
public UndertowRequestUpgradeStrategy() { if (exchangeConstructorWithPeerConnections) { this.peerConnections = Collections.newSetFromMap(new ConcurrentHashMap<WebSocketChannel, Boolean>()); } else { this.peerConnections = null; } }
Example 12
Source File: FeedCleaner.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public void beforeDeleteNodeSite(NodeRef siteNodeRef) { String siteId = (String)nodeService.getProperty(siteNodeRef, ContentModel.PROP_NAME); Set<String> deletedSiteIds = (Set<String>)AlfrescoTransactionSupport.getResource(KEY_DELETED_SITE_IDS); if (deletedSiteIds == null) { deletedSiteIds = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); // Java 6 AlfrescoTransactionSupport.bindResource(KEY_DELETED_SITE_IDS, deletedSiteIds); } deletedSiteIds.add(siteId); AlfrescoTransactionSupport.bindListener(deleteSiteTransactionListener); }
Example 13
Source File: PendingPool.java From teku with Apache License 2.0 | 4 votes |
private Set<Bytes32> createRootSet(final Bytes32 initialValue) { final Set<Bytes32> rootSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); rootSet.add(initialValue); return rootSet; }
Example 14
Source File: DefaultCollectionsProvider.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public <E> Set<E> newIdentitySet() { return Collections.newSetFromMap(newIdentityMap()); }
Example 15
Source File: EquippedEquipmentFacet.java From pcgen with GNU Lesser General Public License v2.1 | 3 votes |
/** * Copies the contents of the EquippedEquipmentFacet from one Player * Character to another Player Character, based on the given CharIDs * representing those Player Characters. * * This is a method in EquippedEquipmentFacet in order to avoid exposing the * mutable Map object to other classes. This should not be inlined, as the * Map is internal information to EquippedEquipmentFacet and should not be * exposed to other classes. * * Note also the copy is a one-time event and no references are maintained * between the Player Characters represented by the given CharIDs (meaning * once this copy takes place, any change to the EquippedEquipmentFacet of * one Player Character will only impact the Player Character where the * EquippedEquipmentFacet was changed). * * @param source * The CharID representing the Player Character from which the * information should be copied * @param copy * The CharID representing the Player Character to which the * information should be copied */ @Override public void copyContents(CharID source, CharID copy) { Set<Equipment> set = (Set<Equipment>) getCache(source); if (set != null) { Set<Equipment> newEquipped = Collections.newSetFromMap(new IdentityHashMap<>()); newEquipped.addAll(set); setCache(copy, newEquipped); } }
Example 16
Source File: AbstractQualifiedListFacet.java From pcgen with GNU Lesser General Public License v2.1 | 3 votes |
/** * Returns a Set of sources for this AbstractQualifiedListFacet, the * PlayerCharacter represented by the given CharID, and the given object. * Will add the given object to the list of items for the PlayerCharacter * represented by the given CharID and will return a new, empty Set if no * information has been set in this AbstractQualifiedListFacet for the given * CharID and given object. Will not return null. * * Note that this method SHOULD NOT be public. The Set object is owned by * AbstractQualifiedListFacet, and since it can be modified, a reference to * that object should not be exposed to any object other than * AbstractQualifiedListFacet. * * @param id * The CharID for which the Set should be returned * @param obj * The object for which the Set of sources should be returned * @return The Set of sources for the given object and Player Character * represented by the given CharID. */ private Set<Object> getConstructingCachedSetFor(CharID id, T obj) { Map<T, Set<Object>> map = getConstructingCachedMap(id); Set<Object> set = map.get(obj); if (set == null) { set = Collections.newSetFromMap(new IdentityHashMap<>()); map.put(obj, set); } return set; }
Example 17
Source File: InvertedRadixTreeIndex.java From cqengine with Apache License 2.0 | 2 votes |
/** * @return A {@link StoredSetBasedResultSet} based on a set backed by {@link ConcurrentHashMap}, as created via * {@link java.util.Collections#newSetFromMap(java.util.Map)} */ public StoredResultSet<O> createValueSet() { return new StoredSetBasedResultSet<O>(Collections.<O>newSetFromMap(new ConcurrentHashMap<O, Boolean>())); }
Example 18
Source File: ConditionallyGrantedAbilityFacet.java From pcgen with GNU Lesser General Public License v2.1 | 2 votes |
/** * Overrides the default behavior of AbstractListFacet, since we need to * ensure we are storing the conditionally granted abilities by their * identity (Ability has old behavior in .equals and Abilities are still * cloned) */ @Override protected Set<CNAbilitySelection> getComponentSet() { return Collections.newSetFromMap(new IdentityHashMap<>()); }
Example 19
Source File: Sets.java From codebuff with BSD 2-Clause "Simplified" License | 2 votes |
/** * Returns a set backed by the specified map. The resulting set displays * the same ordering, concurrency, and performance characteristics as the * backing map. In essence, this factory method provides a {@link Set} * implementation corresponding to any {@link Map} implementation. There is no * need to use this method on a {@link Map} implementation that already has a * corresponding {@link Set} implementation (such as {@link java.util.HashMap} * or {@link java.util.TreeMap}). * * <p>Each method invocation on the set returned by this method results in * exactly one method invocation on the backing map or its {@code keySet} * view, with one exception. The {@code addAll} method is implemented as a * sequence of {@code put} invocations on the backing map. * * <p>The specified map must be empty at the time this method is invoked, * and should not be accessed directly after this method returns. These * conditions are ensured if the map is created empty, passed directly * to this method, and no reference to the map is retained, as illustrated * in the following code fragment: <pre> {@code * * Set<Object> identityHashSet = Sets.newSetFromMap( * new IdentityHashMap<Object, Boolean>());}</pre> * * <p>The returned set is serializable if the backing map is. * * @param map the backing map * @return the set backed by the map * @throws IllegalArgumentException if {@code map} is not empty * @deprecated Use {@link Collections#newSetFromMap} instead. This method * will be removed in December 2017. */ @Deprecated public static <E> Set<E> newSetFromMap(Map<E, Boolean> map) { return Collections.newSetFromMap(map); }
Example 20
Source File: Sets.java From codebuff with BSD 2-Clause "Simplified" License | votes |
/** * Creates a thread-safe set backed by a hash map. The set is backed by a * {@link ConcurrentHashMap} instance, and thus carries the same concurrency * guarantees. * * <p>Unlike {@code HashSet}, this class does NOT allow {@code null} to be * used as an element. The set is serializable. * * @return a new, empty thread-safe {@code Set} * @since 15.0 */ public static <E> Set<E> newConcurrentHashSet() { return Collections.newSetFromMap(new ConcurrentHashMap<E, Boolean>()); }