@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; }
private boolean isMuted(TopicPartition tp, long now) { boolean result = muted.containsKey(tp) && muted.get(tp) > now; if (!result) muted.remove(tp); return result; }
@Override public V put(K key, V value) { if (keyValueMap.containsKey(key)) { valueKeyMap.remove(keyValueMap.get(key)); } valueKeyMap.put(value, key); return keyValueMap.put(key, value); }
@Override public void run() { try { CompletableFuture<Monitor> completableFuture = AbstractMonitorFactory.FUTURES.get(key); AbstractMonitorFactory.MONITORS.put(key, completableFuture.get()); AbstractMonitorFactory.FUTURES.remove(key); } catch (InterruptedException e) { logger.warn("Thread was interrupted unexpectedly, monitor will never be got."); AbstractMonitorFactory.FUTURES.remove(key); } catch (ExecutionException e) { logger.warn("Create monitor failed, monitor data will not be collected until you fix this problem. ", e); } } }
private static Set<WorkerSlot> badSlots(Map<WorkerSlot, List<ExecutorDetails>> existingSlots, int numExecutors, int numWorkers) { if (numWorkers != 0) { Map<Integer, Integer> distribution = Utils.integerDivided(numExecutors, numWorkers); Set<WorkerSlot> slots = new HashSet<WorkerSlot>(); for (Entry<WorkerSlot, List<ExecutorDetails>> entry : existingSlots.entrySet()) { Integer executorCount = entry.getValue().size(); Integer workerCount = distribution.get(executorCount); if (workerCount != null && workerCount > 0) { slots.add(entry.getKey()); workerCount--; distribution.put(executorCount, workerCount); } } for (WorkerSlot slot : slots) { existingSlots.remove(slot); } return existingSlots.keySet(); } return null; }
/** * Add the given singleton factory for building the specified singleton * if necessary. * <p>To be called for eager registration of singletons, e.g. to be able to * resolve circular references. * @param beanName the name of the bean * @param singletonFactory the factory for the singleton object */ protected void addSingletonFactory(String beanName, ObjectFactory<?> singletonFactory) { Assert.notNull(singletonFactory, "Singleton factory must not be null"); synchronized (this.singletonObjects) { if (!this.singletonObjects.containsKey(beanName)) { this.singletonFactories.put(beanName, singletonFactory); this.earlySingletonObjects.remove(beanName); this.registeredSingletons.add(beanName); } } }
public void testRemove() { final Map<K, V> map; final K keyToRemove; try { map = makePopulatedMap(); } catch (UnsupportedOperationException e) { return; } keyToRemove = map.keySet().iterator().next(); if (supportsRemove) { int initialSize = map.size(); V expectedValue = map.get(keyToRemove); V oldValue = map.remove(keyToRemove); assertEquals(expectedValue, oldValue); assertFalse(map.containsKey(keyToRemove)); assertEquals(initialSize - 1, map.size()); } else { try { map.remove(keyToRemove); fail("Expected UnsupportedOperationException."); } catch (UnsupportedOperationException expected) { } } assertInvariants(map); }
private static <K, V> void doDifference( Map<? extends K, ? extends V> left, Map<? extends K, ? extends V> right, Equivalence<? super V> valueEquivalence, Map<K, V> onlyOnLeft, Map<K, V> onlyOnRight, Map<K, V> onBoth, Map<K, MapDifference.ValueDifference<V>> differences) { for (Entry<? extends K, ? extends V> entry : left.entrySet()) { K leftKey = entry.getKey(); V leftValue = entry.getValue(); if (right.containsKey(leftKey)) { V rightValue = onlyOnRight.remove(leftKey); if (valueEquivalence.equivalent(leftValue, rightValue)) { onBoth.put(leftKey, leftValue); } else { differences.put(leftKey, ValueDifferenceImpl.create(leftValue, rightValue)); } } else { onlyOnLeft.put(leftKey, leftValue); } } }
public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } }
/** * 合并用户对namespace的修改 */ private Map<String, String> mergeOverriddenProperties(String namespace, Map<String, String> configurations) { if (addedOrModifiedPropertiesOfNamespace.containsKey(namespace)) { configurations.putAll(addedOrModifiedPropertiesOfNamespace.get(namespace)); } if (deletedKeysOfNamespace.containsKey(namespace)) { for (String k : deletedKeysOfNamespace.get(namespace)) { configurations.remove(k); } } return configurations; }
@CanIgnoreReturnValue private Map<R, V> removeColumn(Object column) { Map<R, V> output = new LinkedHashMap<>(); Iterator<Entry<R, Map<C, V>>> iterator = backingMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<R, Map<C, V>> entry = iterator.next(); V value = entry.getValue().remove(column); if (value != null) { output.put(entry.getKey(), value); if (entry.getValue().isEmpty()) { iterator.remove(); } } } return output; }
public void testStandardEntrySet() throws InvocationTargetException { @SuppressWarnings("unchecked") final Map<String, Boolean> map = mock(Map.class); Map<String, Boolean> forward = new ForwardingMap<String, Boolean>() { @Override protected Map<String, Boolean> delegate() { return map; } @Override public Set<Entry<String, Boolean>> entrySet() { return new StandardEntrySet() { @Override public Iterator<Entry<String, Boolean>> iterator() { return Iterators.emptyIterator(); } }; } }; callAllPublicMethods(new TypeToken<Set<Entry<String, Boolean>>>() {}, forward.entrySet()); // These are the methods specified by StandardEntrySet verify(map, atLeast(0)).clear(); verify(map, atLeast(0)).containsKey(anyObject()); verify(map, atLeast(0)).get(anyObject()); verify(map, atLeast(0)).isEmpty(); verify(map, atLeast(0)).remove(anyObject()); verify(map, atLeast(0)).size(); verifyNoMoreInteractions(map); }
public void testStandardKeySet() throws InvocationTargetException { @SuppressWarnings("unchecked") final Map<String, Boolean> map = mock(Map.class); Map<String, Boolean> forward = new ForwardingMap<String, Boolean>() { @Override protected Map<String, Boolean> delegate() { return map; } @Override public Set<String> keySet() { return new StandardKeySet(); } }; callAllPublicMethods(new TypeToken<Set<String>>() {}, forward.keySet()); // These are the methods specified by StandardKeySet verify(map, atLeast(0)).clear(); verify(map, atLeast(0)).containsKey(anyObject()); verify(map, atLeast(0)).isEmpty(); verify(map, atLeast(0)).remove(anyObject()); verify(map, atLeast(0)).size(); verify(map, atLeast(0)).entrySet(); verifyNoMoreInteractions(map); }
@Override public V put(K key, V value) { if (keyValueMap.containsKey(key)) { valueKeyMap.remove(keyValueMap.get(key)); } valueKeyMap.put(value, key); return keyValueMap.put(key, value); }
@Override public void run() { try { CompletableFuture<Monitor> completableFuture = AbstractMonitorFactory.FUTURES.get(key); AbstractMonitorFactory.MONITORS.put(key, completableFuture.get()); AbstractMonitorFactory.FUTURES.remove(key); } catch (InterruptedException e) { logger.warn("Thread was interrupted unexpectedly, monitor will never be got."); AbstractMonitorFactory.FUTURES.remove(key); } catch (ExecutionException e) { logger.warn("Create monitor failed, monitor data will not be collected until you fix this problem. ", e); } } }
@SuppressWarnings("ReferenceEquality") public Set<String> getInvalidatedClasses(ShadowMap previous) { if (this == previous && shadowPickers.isEmpty()) return Collections.emptySet(); Map<String, ShadowInfo> invalidated = new HashMap<>(overriddenShadows); for (Map.Entry<String, ShadowInfo> entry : previous.overriddenShadows.entrySet()) { String className = entry.getKey(); ShadowInfo previousConfig = entry.getValue(); ShadowInfo currentConfig = invalidated.get(className); if (currentConfig == null) { invalidated.put(className, previousConfig); } else if (previousConfig.equals(currentConfig)) { invalidated.remove(className); } } HashSet<String> classNames = new HashSet<>(invalidated.keySet()); classNames.addAll(shadowPickers.keySet()); return classNames; }