本文整理了Java中java.util.Collections.emptySet()
方法的一些代码示例,展示了Collections.emptySet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.emptySet()
方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:emptySet
[英]Returns a type-safe empty, immutable Set.
[中]返回类型安全的空不可变集。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Set<String> getMetaAnnotationTypes(String annotationName) {
Set<String> metaAnnotationTypes = this.metaAnnotationMap.get(annotationName);
return (metaAnnotationTypes != null ? metaAnnotationTypes : Collections.emptySet());
}
代码示例来源:origin: square/retrofit
private static Set<? extends Annotation> jsonAnnotations(Annotation[] annotations) {
Set<Annotation> result = null;
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(JsonQualifier.class)) {
if (result == null) result = new LinkedHashSet<>();
result.add(annotation);
}
}
return result != null ? unmodifiableSet(result) : Collections.<Annotation>emptySet();
}
}
代码示例来源:origin: jenkinsci/jenkins
@Override
protected Iterable<? extends String> getEdges(String n) {
// return variables referred from the variable.
if (!refereeSetMap.containsKey(n)) {
// there is a case a non-existing variable is referred...
return Collections.emptySet();
}
return refereeSetMap.get(n);
}
};
代码示例来源:origin: apache/geode
Set getDependencySet(CompiledValue cv, boolean readOnly) {
Set set = (Set) this.dependencyGraph.get(cv);
if (set == null) {
if (readOnly)
return Collections.emptySet();
set = new HashSet(1);
this.dependencyGraph.put(cv, set);
}
return set;
}
代码示例来源:origin: square/okhttp
/**
* Returns the distinct query parameter names in this URL, like {@code ["a", "b"]} for {@code
* http://host/?a=apple&b=banana}. If this URL has no query this returns the empty set.
*
* <p><table summary="">
* <tr><th>URL</th><th>{@code queryParameterNames()}</th></tr>
* <tr><td>{@code http://host/}</td><td>{@code []}</td></tr>
* <tr><td>{@code http://host/?}</td><td>{@code [""]}</td></tr>
* <tr><td>{@code http://host/?a=apple&k=key+lime}</td><td>{@code ["a", "k"]}</td></tr>
* <tr><td>{@code http://host/?a=apple&a=apricot}</td><td>{@code ["a"]}</td></tr>
* <tr><td>{@code http://host/?a=apple&b}</td><td>{@code ["a", "b"]}</td></tr>
* </table>
*/
public Set<String> queryParameterNames() {
if (queryNamesAndValues == null) return Collections.emptySet();
Set<String> result = new LinkedHashSet<>();
for (int i = 0, size = queryNamesAndValues.size(); i < size; i += 2) {
result.add(queryNamesAndValues.get(i));
}
return Collections.unmodifiableSet(result);
}
代码示例来源:origin: skylot/jadx
private Set<String> getAncestors(String clsName) {
Set<String> result = ancestorCache.get(clsName);
if (result != null) {
return result;
}
NClass cls = nameMap.get(clsName);
if (cls == null) {
missingClasses.add(clsName);
return Collections.emptySet();
}
result = new HashSet<>();
addAncestorsNames(cls, result);
if (result.isEmpty()) {
result = Collections.emptySet();
}
ancestorCache.put(clsName, result);
return result;
}
代码示例来源:origin: spring-projects/spring-framework
public Collection<SourceClass> getAnnotationAttributes(String annType, String attribute) throws IOException {
Map<String, Object> annotationAttributes = this.metadata.getAnnotationAttributes(annType, true);
if (annotationAttributes == null || !annotationAttributes.containsKey(attribute)) {
return Collections.emptySet();
}
String[] classNames = (String[]) annotationAttributes.get(attribute);
Set<SourceClass> result = new LinkedHashSet<>();
for (String className : classNames) {
result.add(getRelated(className));
}
return result;
}
代码示例来源:origin: pmd/pmd
private Set<String> styleForDepth(int depth, boolean inlineHighlight) {
if (depth < 0) {
// that's the style when we're outside any node
return Collections.emptySet();
} else {
// Caching reduces the number of sets used by this step of the overlaying routine to
// only a few. The number is probably blowing up during the actual spans overlaying
// in StyleContext#recomputePainting
DEPTH_STYLE_CACHE.putIfAbsent(style, new HashMap<>());
Map<Integer, Map<Boolean, Set<String>>> depthToStyle = DEPTH_STYLE_CACHE.get(style);
depthToStyle.putIfAbsent(depth, new HashMap<>());
Map<Boolean, Set<String>> isInlineToStyle = depthToStyle.get(depth);
if (isInlineToStyle.containsKey(inlineHighlight)) {
return isInlineToStyle.get(inlineHighlight);
}
Set<String> s = new HashSet<>(style);
s.add("depth-" + depth);
if (inlineHighlight) {
// inline highlight can be used to add boxing around a node if it wouldn't be ugly
s.add("inline-highlight");
}
isInlineToStyle.put(inlineHighlight, s);
return s;
}
}
代码示例来源:origin: alibaba/cobar
/**
* @param orig if null, return intersect
*/
public static Set<? extends Object> intersectSet(Set<? extends Object> orig, Set<? extends Object> intersect) {
if (orig == null)
return intersect;
if (intersect == null || orig.isEmpty())
return Collections.emptySet();
Set<Object> set = new HashSet<Object>(orig.size());
for (Object p : orig) {
if (intersect.contains(p))
set.add(p);
}
return set;
}
}
代码示例来源:origin: bumptech/glide
if (values.size() != 1) {
throw new IllegalArgumentException("Expected single value, but found: " + values);
return Collections.emptySet();
Set<String> result = new HashSet<>(values.size());
for (Object current : values) {
result.add(getExcludedModuleClassFromAnnotationAttribute(clazz, current));
return Collections.singleton(classType.toString());
代码示例来源:origin: qunarcorp/qmq
public Set<ClientMetaInfo> aliveClientsOf(String subject) {
final Map<ClientMetaInfo, Long> clients = allClients.get(subject);
if (clients == null || clients.isEmpty()) {
return Collections.emptySet();
}
final long now = System.currentTimeMillis();
final Set<ClientMetaInfo> result = new HashSet<>();
for (Map.Entry<ClientMetaInfo, Long> entry : clients.entrySet()) {
if (entry.getValue() != null && now - entry.getValue() < EXPIRE_TIME_MS) {
result.add(entry.getKey());
}
}
return result;
}
代码示例来源:origin: spring-projects/spring-security-oauth
public OAuth2Authentication extractAuthentication(Map<String, ?> map) {
Map<String, String> parameters = new HashMap<String, String>();
Set<String> scope = extractScope(map);
Authentication user = userTokenConverter.extractAuthentication(map);
String clientId = (String) map.get(clientIdAttribute);
parameters.put(clientIdAttribute, clientId);
if (includeGrantType && map.containsKey(GRANT_TYPE)) {
parameters.put(GRANT_TYPE, (String) map.get(GRANT_TYPE));
}
Set<String> resourceIds = new LinkedHashSet<String>(map.containsKey(AUD) ? getAudience(map)
: Collections.<String>emptySet());
Collection<? extends GrantedAuthority> authorities = null;
if (user==null && map.containsKey(AUTHORITIES)) {
@SuppressWarnings("unchecked")
String[] roles = ((Collection<String>)map.get(AUTHORITIES)).toArray(new String[0]);
authorities = AuthorityUtils.createAuthorityList(roles);
}
OAuth2Request request = new OAuth2Request(parameters, clientId, authorities, true, scope, resourceIds, null, null,
null);
return new OAuth2Authentication(request, user);
}
代码示例来源:origin: apache/kafka
PartitionInfo part1 = new PartitionInfo(topic, 1, node1, null, null);
Cluster cluster = new Cluster(null, Collections.singletonList(node1), Collections.singletonList(part1),
Collections.emptySet(), Collections.emptySet());
accumulator.append(tp1, time.milliseconds(), "key".getBytes(),
"value".getBytes(), Record.EMPTY_HEADERS, null, MAX_BLOCK_TIMEOUT);
Map<Integer, List<ProducerBatch>> drainedBatches = accumulator.drain(cluster, Collections.singleton(node1),
Integer.MAX_VALUE,
time.milliseconds());
assertTrue(drainedBatches.containsKey(node1.id()));
assertEquals(1, drainedBatches.get(node1.id()).size());
assertTrue(transactionManager.hasAbortableError());
代码示例来源:origin: wildfly/wildfly
@Override
public Set<InetSocketAddress> allLocalAddresses() {
try {
final Set<SocketAddress> allLocalAddresses = sch.getAllLocalAddresses();
final Set<InetSocketAddress> addresses = new LinkedHashSet<InetSocketAddress>(allLocalAddresses.size());
for (SocketAddress socketAddress : allLocalAddresses) {
addresses.add((InetSocketAddress) socketAddress);
}
return addresses;
} catch (Throwable ignored) {
return Collections.emptySet();
}
}
代码示例来源:origin: apache/kafka
@Test
public void testDeleteConsumerGroups() throws Exception {
final HashMap<Integer, Node> nodes = new HashMap<>();
nodes.put(0, new Node(0, "localhost", 8121));
final Cluster cluster =
new Cluster(
"mockClusterId",
nodes.values(),
Collections.<PartitionInfo>emptyList(),
Collections.<String>emptySet(),
Collections.<String>emptySet(), nodes.get(0));
final List<String> groupIds = singletonList("group-0");
try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(cluster)) {
env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
//Retriable FindCoordinatorResponse errors should be retried
env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.COORDINATOR_NOT_AVAILABLE, Node.noNode()));
env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.COORDINATOR_LOAD_IN_PROGRESS, Node.noNode()));
env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
final Map<String, Errors> response = new HashMap<>();
response.put("group-0", Errors.NONE);
env.kafkaClient().prepareResponse(new DeleteGroupsResponse(response));
final DeleteConsumerGroupsResult result = env.adminClient().deleteConsumerGroups(groupIds);
final KafkaFuture<Void> results = result.deletedGroups().get("group-0");
assertNull(results.get());
//should throw error for non-retriable errors
env.kafkaClient().prepareResponse(new FindCoordinatorResponse(Errors.GROUP_AUTHORIZATION_FAILED, Node.noNode()));
final DeleteConsumerGroupsResult errorResult = env.adminClient().deleteConsumerGroups(groupIds);
TestUtils.assertFutureError(errorResult.deletedGroups().get("group-0"), GroupAuthorizationException.class);
}
}
代码示例来源:origin: square/okhttp
/**
* Returns the names of the request headers that need to be checked for equality when caching.
*/
public static Set<String> varyFields(Headers responseHeaders) {
Set<String> result = Collections.emptySet();
for (int i = 0, size = responseHeaders.size(); i < size; i++) {
if (!"Vary".equalsIgnoreCase(responseHeaders.name(i))) continue;
String value = responseHeaders.value(i);
if (result.isEmpty()) {
result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
}
for (String varyField : value.split(",")) {
result.add(varyField.trim());
}
}
return result;
}
代码示例来源:origin: org.mockito/mockito-core
private void assureCanReadMockito(Set<Class<?>> types) {
if (redefineModule == null) {
return;
}
Set<Object> modules = new HashSet<Object>();
try {
Object target = getModule.invoke(Class.forName("org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher", false, null));
for (Class<?> type : types) {
Object module = getModule.invoke(type);
if (!modules.contains(module) && !(Boolean) canRead.invoke(module, target)) {
modules.add(module);
}
}
for (Object module : modules) {
redefineModule.invoke(instrumentation, module, Collections.singleton(target),
Collections.emptyMap(), Collections.emptyMap(), Collections.emptySet(), Collections.emptyMap());
}
} catch (Exception e) {
throw new IllegalStateException(join("Could not adjust module graph to make the mock instance dispatcher visible to some classes",
"",
"At least one of those modules: " + modules + " is not reading the unnamed module of the bootstrap loader",
"Without such a read edge, the classes that are redefined to become mocks cannot access the mock dispatcher.",
"To circumvent this, Mockito attempted to add a read edge to this module what failed for an unexpected reason"), e);
}
}
代码示例来源:origin: spring-projects/spring-framework
private Set<String> getPrefixesSet(String namespaceUri) {
Assert.notNull(namespaceUri, "No namespaceUri given");
if (this.defaultNamespaceUri.equals(namespaceUri)) {
return Collections.singleton(XMLConstants.DEFAULT_NS_PREFIX);
}
else if (XMLConstants.XML_NS_URI.equals(namespaceUri)) {
return Collections.singleton(XMLConstants.XML_NS_PREFIX);
}
else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceUri)) {
return Collections.singleton(XMLConstants.XMLNS_ATTRIBUTE);
}
else {
Set<String> prefixes = this.namespaceUriToPrefixes.get(namespaceUri);
return (prefixes != null ? Collections.unmodifiableSet(prefixes) : Collections.emptySet());
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
boolean canHaveRootAttributeOnReadOnlyFS(String name) {
Set<String> tmp = rootAttributes;
if (tmp == null) {
tmp = new HashSet<String>();
for (FileSystem fs : getDelegates()) {
if (fs == null) {
continue;
}
if (!fs.isReadOnly()) {
continue;
}
Enumeration<String> en = fs.getRoot().getAttributes();
while (en.hasMoreElements()) {
tmp.add(en.nextElement());
}
rootAttributes = tmp;
}
}
if (tmp == Collections.<String>emptySet()) {
return true;
}
return tmp.contains(name);
}
}
代码示例来源:origin: google/guava
public void testForMapRemoveAll() {
Map<String, Integer> map = Maps.newHashMap();
map.put("foo", 1);
map.put("bar", 2);
map.put("cow", 3);
Multimap<String, Integer> multimap = Multimaps.forMap(map);
assertEquals(3, multimap.size());
assertEquals(Collections.emptySet(), multimap.removeAll("dog"));
assertEquals(3, multimap.size());
assertTrue(multimap.containsKey("bar"));
assertEquals(Collections.singleton(2), multimap.removeAll("bar"));
assertEquals(2, multimap.size());
assertFalse(multimap.containsKey("bar"));
}
内容来源于网络,如有侵权,请联系作者删除!