@Override public void put(String componentName, String key, Object value) { Map<String, Object> componentData = data.get(componentName); if (null == componentData) { data.putIfAbsent(componentName, new ConcurrentHashMap<String, Object>()); componentData = data.get(componentName); } componentData.put(key, value); }
/** * Create a new {@code Message.Builder} instance for the given class. * <p>This method uses a ConcurrentHashMap for caching method lookups. */ private static Message.Builder getMessageBuilder(Class<?> clazz) throws Exception { Method method = methodCache.get(clazz); if (method == null) { method = clazz.getMethod("newBuilder"); methodCache.put(clazz, method); } return (Message.Builder) method.invoke(clazz); }
@Override public void remove(String componentName, String key) { if (!data.containsKey(componentName)) { return; } data.get(componentName).remove(key); }
@Override public Object get(String componentName, String key) { if (!data.containsKey(componentName)) { return null; } return data.get(componentName).get(key); }
@SuppressWarnings("unchecked") // it's a subtype map @Nullable private static <T> Class<? extends T> getImplementation(Class<T> type) { return (Class<? extends T>) implementations.get(type); }
public void testRemove_noneRemaining() { int countToRemove = 30; AtomicInteger current = new AtomicInteger(countToRemove); when(backingMap.get(KEY)).thenReturn(current); // it's ok if removal fails: another thread may have done the remove when(backingMap.remove(KEY, current)).thenReturn(false); assertEquals(countToRemove, multiset.remove(KEY, countToRemove)); assertEquals(0, current.get()); }
/** * set value. * * @param key * @param value */ public void set(String key, Object value) { values.put(key, value); }
@CanIgnoreReturnValue @Override public boolean remove(Object key, Object value) { return delegate().remove(key, value); }
public static <T> ProviderInvokerWrapper<T> getProviderWrapper(URL registeredProviderUrl, Invoker<T> invoker) { String serviceUniqueName = registeredProviderUrl.getServiceKey(); ConcurrentMap<Invoker, ProviderInvokerWrapper> invokers = providerInvokers.get(serviceUniqueName); if (invokers == null) { return null; } for (Invoker inv : invokers.keySet()) { if (inv == invoker) { return invokers.get(inv); } } return null; }
@CanIgnoreReturnValue @Override public V putIfAbsent(K key, V value) { return delegate().putIfAbsent(key, value); }
/** * Gets all beans of {@link ReferenceBean} * * @return non-null {@link Collection} * @since 2.5.9 */ public Collection<ReferenceBean<?>> getReferenceBeans() { return this.referenceBeansCache.values(); }
final Iterable<Method> getInstanceMethods(Class<?> cls) { ConcurrentMap<Signature, Method> map = Maps.newConcurrentMap(); for (Method method : getVisibleMethods(cls)) { if (!Invokable.from(method).isStatic()) { map.putIfAbsent(new Signature(method), method); } } return map.values(); }
/** * Clear the cache. */ protected void clearTransactionManagerCache() { this.transactionManagerCache.clear(); this.beanFactory = null; }
public void testRemove_byKey() { for (LoadingCache<Object, Object> cache : caches()) { // don't let the entries get GCed List<Entry<Object, Object>> warmed = warmUp(cache); for (int i = WARMUP_MIN; i < WARMUP_MAX; i++) { Entry<Object, Object> entry = warmed.get(i - WARMUP_MIN); Object key = entry.getKey(); assertEquals(entry.getValue(), cache.asMap().remove(key)); assertNull(cache.asMap().remove(key)); assertFalse(cache.asMap().containsKey(key)); } checkEmpty(cache); } }
/** * Returns an iterator over the elements in this set. The elements are * returned in no particular order. * * @return an Iterator over the elements in this set * @see ConcurrentModificationException */ @Override public Iterator<E> iterator() { return map.keySet().iterator(); }
@Override public void destroy() throws Exception { for (ReferenceBean referenceBean : referenceBeansCache.values()) { if (logger.isInfoEnabled()) { logger.info(referenceBean + " was destroying!"); } referenceBean.destroy(); } injectionMetadataCache.clear(); referenceBeansCache.clear(); if (logger.isInfoEnabled()) { logger.info(getClass() + " was destroying!"); } }
/** * Returns <tt>true</tt> if this set contains the specified element. More * formally, returns <tt>true</tt> if and only if this set contains an * element <tt>e</tt> such that * <tt>(o==null ? e==null : o.equals(e))</tt>. * * @param o element whose presence in this set is to be tested * @return <tt>true</tt> if this set contains the specified element */ @Override public boolean contains(Object o) { return map.containsKey(o); }
public void testClear() { for (LoadingCache<Key, String> cache : caches()) { Key key = new Key(1); String value = key.toString(); assertSame(value, cache.getUnchecked(key)); assertFalse(cache.asMap().isEmpty()); cache.invalidateAll(); assertEquals(0, cache.size()); assertTrue(cache.asMap().isEmpty()); assertFalse(cache.asMap().containsKey(key)); assertFalse(cache.asMap().containsValue(value)); } }
static void checkEmpty(Cache<?, ?> cache) { assertEquals(0, cache.size()); assertFalse(cache.asMap().containsKey(null)); assertFalse(cache.asMap().containsKey(6)); assertFalse(cache.asMap().containsValue(null)); assertFalse(cache.asMap().containsValue(6)); checkEmpty(cache.asMap()); }
public void testAdd_zero() { final int INITIAL_COUNT = 32; when(backingMap.get(KEY)).thenReturn(new AtomicInteger(INITIAL_COUNT)); assertEquals(INITIAL_COUNT, multiset.add(KEY, 0)); }