Refine search
void addIndexDiff( MutableLongDiffSets diff ) { if ( indexDiffs == null ) { indexDiffs = Collections.newSetFromMap( new IdentityHashMap<>() ); } indexDiffs.add( diff ); }
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<InternalThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<InternalThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<InternalThreadLocal<?>>) v; } variablesToRemove.add(variable); }
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<InternalThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<InternalThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<InternalThreadLocal<?>>) v; } variablesToRemove.add(variable); }
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<FastThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<FastThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<FastThreadLocal<?>>) v; } variablesToRemove.add(variable); }
public void addNode(final String clusterName, final String nodeName, URI registeredBy) { effectiveAuthURIs.putIfAbsent(clusterName, registeredBy); clusterNodes.computeIfAbsent(clusterName, ignored -> Collections.newSetFromMap(new ConcurrentHashMap<>())).add(nodeName); }
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<FastThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<FastThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<FastThreadLocal<?>>) v; } variablesToRemove.add(variable); }
/** * Returns collection of all annotation types attached to a given annotated element that have the provided meta * annotation attached. * * @param annotatedElement annotated element. * @param metaAnnotation meta annotation attached to the annotation types we are looking for (if null, annotation * types of all attached annotations will be returned). * @return list of annotation types with a given meta annotation */ public static Collection<Class<? extends Annotation>> getAnnotationTypes(final AnnotatedElement annotatedElement, final Class<? extends Annotation> metaAnnotation) { final Set<Class<? extends Annotation>> result = Collections.newSetFromMap(new IdentityHashMap<>()); for (final Annotation a : annotatedElement.getAnnotations()) { final Class<? extends Annotation> aType = a.annotationType(); if (metaAnnotation == null || aType.getAnnotation(metaAnnotation) != null) { result.add(aType); } } return result; }
/** * Returns collection of all annotation types attached to a given annotated element that have the provided meta * annotation attached. * * @param annotatedElement annotated element. * @param metaAnnotation meta annotation attached to the annotation types we are looking for (if null, annotation * types of all attached annotations will be returned). * @return list of annotation types with a given meta annotation */ public static Collection<Class<? extends Annotation>> getAnnotationTypes(final AnnotatedElement annotatedElement, final Class<? extends Annotation> metaAnnotation) { final Set<Class<? extends Annotation>> result = Collections.newSetFromMap(new IdentityHashMap<>()); for (final Annotation a : annotatedElement.getAnnotations()) { final Class<? extends Annotation> aType = a.annotationType(); if (metaAnnotation == null || aType.getAnnotation(metaAnnotation) != null) { result.add(aType); } } return result; }
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 }
public static void test() { Set<String> s = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>()); s.add("Foo"); PoJo p = new PoJo("Foo"); s.remove(p); // <- bug } public static void test2() {
public static void test2() { List<Set<String>> sets = new ArrayList<Set<String>>(); for (int i = 0; i < 10; ++i) { sets.add( Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>())); sets.get(i).add("Foo"); } PoJo p = new PoJo("Foo"); sets.get(5).remove(p); // <- bug } }
/** * Returns a stream consisting of the distinct elements (according to * {@link Object#equals(Object)}) of this stream based on the value only. If * the same value is encountered multiple times, only the first occurence * will be allowed to pass. * <p> * This is a stateful intermediate operation. * * @return the new stream */ public MapStream<K, V> distinctValues() { final Set<V> temp = newSetFromMap(new ConcurrentHashMap<>()); inner = inner.flatMap(e -> temp.add(e.getValue()) ? Stream.of(e) : Stream.empty() ); return this; }
/** * Returns a stream consisting of the distinct elements (according to * {@link Object#equals(Object)}) of this stream based on the key only. If * the same key is encountered multiple times, only the first occurence will * be allowed to pass. * <p> * This is a stateful intermediate operation. * * @return the new stream */ public MapStream<K, V> distinctKeys() { final Set<K> temp = newSetFromMap(new ConcurrentHashMap<>()); inner = inner.flatMap(e -> temp.add(e.getKey()) ? Stream.of(e) : Stream.empty() ); return this; }
/** * Add group to cache * * @param group name of the group to add to cache * @param users list of users for a given group */ public static void add(String group, List<String> users) { for (String user : users) { Set<String> userGroups = userToNetgroupsMap.get(user); // ConcurrentHashMap does not allow null values; // So null value check can be used to check if the key exists if (userGroups == null) { //Generate a ConcurrentHashSet (backed by the keyset of the ConcurrentHashMap) userGroups = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>()); Set<String> currentSet = userToNetgroupsMap.putIfAbsent(user, userGroups); if (currentSet != null) { userGroups = currentSet; } } userGroups.add(group); } } }
/** * Stores the given connection record in the list of active connections * associated with the object having the given identifier. * * @param identifier * The identifier of the object being connected to. * * @param record * The record associated with the active connection. */ public void put(String identifier, ActiveConnectionRecord record) { synchronized (records) { // Get set of active connection records, creating if necessary Set<ActiveConnectionRecord> connections = records.get(identifier); if (connections == null) { connections = Collections.synchronizedSet(Collections.newSetFromMap(new LinkedHashMap<ActiveConnectionRecord, Boolean>())); records.put(identifier, connections); } // Add active connection connections.add(record); } }
private <K, V> void join(ConcurrentMap<K, Set<V>> map, K key, V value) { Set<V> clients = map.get(key); if (clients == null) { clients = Collections.newSetFromMap(PlatformDependent.<V, Boolean>newConcurrentHashMap()); Set<V> oldClients = map.putIfAbsent(key, clients); if (oldClients != null) { clients = oldClients; } } clients.add(value); // object may be changed due to other concurrent call if (clients != map.get(key)) { // re-join if queue has been replaced join(map, key, value); } }
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, FastThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<FastThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<FastThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<FastThreadLocal<?>>) v; } variablesToRemove.add(variable); }
public void addMonitorListener( Object monitorListener, String... tags ) { MonitorListenerInvocationHandler monitorListenerInvocationHandler = createInvocationHandler( monitorListener, tags ); List<Class<?>> listenerInterfaces = getAllInterfaces( monitorListener ); methodsStream( listenerInterfaces ).forEach( method -> { Set<MonitorListenerInvocationHandler> methodHandlers = methodMonitorListeners.computeIfAbsent( method, f -> Collections.newSetFromMap( new ConcurrentHashMap<>() ) ); methodHandlers.add( monitorListenerInvocationHandler ); } ); monitoredInterfaces.addAll( listenerInterfaces ); }
private void addCnxn(NIOServerCnxn cnxn) throws IOException { InetAddress addr = cnxn.getSocketAddress(); if (addr == null) { throw new IOException("Socket of " + cnxn + " has been closed"); } Set<NIOServerCnxn> set = ipMap.get(addr); if (set == null) { // in general we will see 1 connection from each // host, setting the initial cap to 2 allows us // to minimize mem usage in the common case // of 1 entry -- we need to set the initial cap // to 2 to avoid rehash when the first entry is added // Construct a ConcurrentHashSet using a ConcurrentHashMap set = Collections.newSetFromMap( new ConcurrentHashMap<NIOServerCnxn, Boolean>(2)); // Put the new set in the map, but only if another thread // hasn't beaten us to it Set<NIOServerCnxn> existingSet = ipMap.putIfAbsent(addr, set); if (existingSet != null) { set = existingSet; } } set.add(cnxn); cnxns.add(cnxn); touchCnxn(cnxn); }
@SuppressWarnings("unchecked") private static void addToVariablesToRemove(InternalThreadLocalMap threadLocalMap, InternalThreadLocal<?> variable) { Object v = threadLocalMap.indexedVariable(variablesToRemoveIndex); Set<InternalThreadLocal<?>> variablesToRemove; if (v == InternalThreadLocalMap.UNSET || v == null) { variablesToRemove = Collections.newSetFromMap(new IdentityHashMap<InternalThreadLocal<?>, Boolean>()); threadLocalMap.setIndexedVariable(variablesToRemoveIndex, variablesToRemove); } else { variablesToRemove = (Set<InternalThreadLocal<?>>) v; } variablesToRemove.add(variable); }