本文整理了Java中java.util.Collections.newSetFromMap()
方法的一些代码示例,展示了Collections.newSetFromMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.newSetFromMap()
方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:newSetFromMap
[英]Returns a set backed by map.
[中]返回由映射支持的集。
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!