Tabnine Logo
Collections.newSetFromMap
Code IndexAdd Tabnine to your IDE (free)

How to use
newSetFromMap
method
in
java.util.Collections

Best Java code snippets using java.util.Collections.newSetFromMap (Showing top 20 results out of 4,077)

Refine searchRefine arrow

  • Set.add
origin: neo4j/neo4j

void addIndexDiff( MutableLongDiffSets diff )
{
  if ( indexDiffs == null )
  {
    indexDiffs = Collections.newSetFromMap( new IdentityHashMap<>() );
  }
  indexDiffs.add( diff );
}
origin: apache/incubator-dubbo

@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);
}
origin: apache/incubator-dubbo

@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);
}
origin: netty/netty

@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);
}
origin: wildfly/wildfly

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);
}
origin: redisson/redisson

@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);
}
origin: jersey/jersey

/**
 * 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;
}
origin: jersey/jersey

/**
 * 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;
}
origin: spotbugs/spotbugs

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
}
origin: spotbugs/spotbugs

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() {
origin: spotbugs/spotbugs

  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
  }
}
origin: speedment/speedment

/**
 * 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;
}

origin: speedment/speedment

/**
 * 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;
}

origin: org.apache.hadoop/hadoop-common

 /**
  * 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);
  }
 }
}
origin: glyptodon/guacamole-client

/**
 * 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);
  }
}
origin: mrniko/netty-socketio

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);
  }
}
origin: wildfly/wildfly

@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);
}
origin: neo4j/neo4j

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 );
}
origin: apache/zookeeper

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);
}
origin: fengjiachun/Jupiter

@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);
}
java.utilCollectionsnewSetFromMap

Javadoc

Returns a set backed by map.

Popular methods of Collections

  • emptyList
    Returns the empty list (immutable). This list is serializable.This example illustrates the type-safe
  • sort
  • singletonList
    Returns an immutable list containing only the specified object. The returned list is serializable.
  • unmodifiableList
    Returns an unmodifiable view of the specified list. This method allows modules to provide users with
  • emptyMap
    Returns the empty map (immutable). This map is serializable.This example illustrates the type-safe w
  • emptySet
    Returns the empty set (immutable). This set is serializable. Unlike the like-named field, this metho
  • unmodifiableMap
    Returns an unmodifiable view of the specified map. This method allows modules to provide users with
  • singleton
    Returns an immutable set containing only the specified object. The returned set is serializable.
  • unmodifiableSet
    Returns an unmodifiable view of the specified set. This method allows modules to provide users with
  • singletonMap
    Returns an immutable map, mapping only the specified key to the specified value. The returned map is
  • addAll
    Adds all of the specified elements to the specified collection. Elements to be added may be specifie
  • reverse
    Reverses the order of the elements in the specified list. This method runs in linear time.
  • addAll,
  • reverse,
  • unmodifiableCollection,
  • shuffle,
  • enumeration,
  • list,
  • synchronizedMap,
  • synchronizedList,
  • reverseOrder,
  • emptyIterator

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onCreateOptionsMenu (Activity)
  • getExternalFilesDir (Context)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now