本文整理了Java中java.util.Map.isEmpty()
方法的一些代码示例,展示了Map.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.isEmpty()
方法的具体详情如下:
包路径:java.util.Map
类名称:Map
方法名:isEmpty
[英]Returns whether this map is empty.
[中]返回此映射是否为空。
代码示例来源:origin: google/guava
Itr() {
keyIterator = map.entrySet().iterator();
key = null;
collection = null;
valueIterator = Iterators.emptyModifiableIterator();
}
代码示例来源:origin: skylot/jadx
private void attachSourceLine(int decompiledLine, int sourceLine) {
if (lineMap.isEmpty()) {
lineMap = new TreeMap<>();
}
lineMap.put(decompiledLine, sourceLine);
}
代码示例来源:origin: google/guava
@VisibleForTesting
static char[][] createReplacementArray(Map<Character, String> map) {
checkNotNull(map); // GWT specific check (do not optimize)
if (map.isEmpty()) {
return EMPTY_REPLACEMENT_ARRAY;
}
char max = Collections.max(map.keySet());
char[][] replacements = new char[max + 1][];
for (char c : map.keySet()) {
replacements[c] = map.get(c).toCharArray();
}
return replacements;
}
代码示例来源:origin: stanfordnlp/CoreNLP
public Map<String, String> classORRestrictionsAsString(){
if(classORrestrictions== null || classORrestrictions.isEmpty())
return null;
Map<String, String> str = new HashMap<>();
for(Map.Entry<Class, String> en: classORrestrictions.entrySet()){
str.put(class2KeyMapping.get(en.getKey()), en.getValue());
}
return str;
}
代码示例来源:origin: org.assertj/assertj-core
private static boolean noNonMatchingModifier(Set<String> expectedMethodNames, Map<String, Integer> methodsModifier,
Map<String, String> nonMatchingModifiers, int modifier) {
for (String method : methodsModifier.keySet()) {
if (expectedMethodNames.contains(method) && (methodsModifier.get(method) & modifier) == 0) {
nonMatchingModifiers.put(method, Modifier.toString(methodsModifier.get(method)));
}
}
return nonMatchingModifiers.isEmpty();
}
代码示例来源:origin: google/guava
@CanIgnoreReturnValue
private Map<R, V> removeColumn(Object column) {
Map<R, V> output = new LinkedHashMap<>();
Iterator<Entry<R, Map<C, V>>> iterator = backingMap.entrySet().iterator();
while (iterator.hasNext()) {
Entry<R, Map<C, V>> entry = iterator.next();
V value = entry.getValue().remove(column);
if (value != null) {
output.put(entry.getKey(), value);
if (entry.getValue().isEmpty()) {
iterator.remove();
}
}
}
return output;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Merge a single hint into a map of hints, possibly creating and copying
* all hints into a new map, or otherwise if the map of hints is empty,
* creating a new single entry map.
* @param hints a map of hints to be merge
* @param hintName the hint name to merge
* @param hintValue the hint value to merge
* @return a single map with all hints
*/
public static Map<String, Object> merge(Map<String, Object> hints, String hintName, Object hintValue) {
if (hints.isEmpty()) {
return Collections.singletonMap(hintName, hintValue);
}
else {
Map<String, Object> result = new HashMap<>(hints.size() + 1);
result.putAll(hints);
result.put(hintName, hintValue);
return result;
}
}
代码示例来源:origin: google/guava
public void testAsMapEmpty() {
Set<String> strings = ImmutableSet.of();
Map<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION);
assertThat(map.entrySet()).isEmpty();
assertTrue(map.isEmpty());
assertNull(map.get("five"));
}
代码示例来源:origin: mpusher/mpush
@Override
public <T> Map<String, T> hgetAll(String key, Class<T> clazz) {
Map<String, Object> m = (Map) cache.get(key);
if (m == null || m.isEmpty()) return Collections.emptyMap();
Map<String, T> result = new HashMap<>();
for (Map.Entry<String, Object> o : m.entrySet()) {
result.put(o.getKey(), Jsons.fromJson(String.valueOf(o.getValue()), clazz));
}
return result;
}
代码示例来源:origin: spring-projects/spring-framework
protected void detectResourceHandlers(ApplicationContext appContext) {
Map<String, SimpleUrlHandlerMapping> beans = appContext.getBeansOfType(SimpleUrlHandlerMapping.class);
List<SimpleUrlHandlerMapping> mappings = new ArrayList<>(beans.values());
AnnotationAwareOrderComparator.sort(mappings);
for (SimpleUrlHandlerMapping mapping : mappings) {
for (String pattern : mapping.getHandlerMap().keySet()) {
Object handler = mapping.getHandlerMap().get(pattern);
if (handler instanceof ResourceHttpRequestHandler) {
ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler;
this.handlerMap.put(pattern, resourceHandler);
}
}
}
if (this.handlerMap.isEmpty()) {
logger.trace("No resource handling mappings found");
}
}
代码示例来源:origin: prestodb/presto
public void setLocalDefinitions(Map<Class<?>, Class<?>> sourceMixins) {
if (sourceMixins == null || sourceMixins.isEmpty()) {
_localMixIns = null;
} else {
Map<ClassKey,Class<?>> mixIns = new HashMap<ClassKey,Class<?>>(sourceMixins.size());
for (Map.Entry<Class<?>,Class<?>> en : sourceMixins.entrySet()) {
mixIns.put(new ClassKey(en.getKey()), en.getValue());
}
_localMixIns = mixIns;
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
if (this.proxyTypes.isEmpty()) {
return null;
}
Object cacheKey = getCacheKey(beanClass, beanName);
return this.proxyTypes.get(cacheKey);
}
代码示例来源:origin: jenkinsci/jenkins
private boolean hasMatchingEnvVars2(Map<String,String> modelEnvVar) throws WindowsOSProcessException {
if(modelEnvVar.isEmpty())
// sanity check so that we don't start rampage.
return false;
SortedMap<String,String> envs = getEnvironmentVariables2();
for (Entry<String,String> e : modelEnvVar.entrySet()) {
String v = envs.get(e.getKey());
if(v==null || !v.equals(e.getValue()))
return false; // no match
}
return true;
}
}
代码示例来源:origin: skylot/jadx
private Object attachAnnotation(Object obj, CodePosition pos) {
if (annotations.isEmpty()) {
annotations = new HashMap<>();
}
return annotations.put(pos, obj);
}
代码示例来源:origin: apache/hbase
private void mergeAssignmentMaps(Map<ServerName, List<RegionInfo>> assignmentMap,
Map<ServerName, List<RegionInfo>> otherAssignments) {
if (otherAssignments == null || otherAssignments.isEmpty()) {
return;
}
for (Entry<ServerName, List<RegionInfo>> entry : otherAssignments.entrySet()) {
ServerName sn = entry.getKey();
List<RegionInfo> regionsList = entry.getValue();
if (assignmentMap.get(sn) == null) {
assignmentMap.put(sn, Lists.newArrayList(regionsList));
} else {
assignmentMap.get(sn).addAll(regionsList);
}
}
}
代码示例来源:origin: apache/geode
protected void initializeFieldAnalyzers(Map<String, Analyzer> fieldAnalyzers) {
this.fieldAnalyzers = new HashMap<>();
for (String field : fieldNames) {
if (fieldAnalyzers != null && !fieldAnalyzers.isEmpty()) {
this.fieldAnalyzers.put(field,
fieldAnalyzers.get(field) == null ? StandardAnalyzer.class.getSimpleName()
: fieldAnalyzers.get(field).getClass().getSimpleName());
} else {
this.fieldAnalyzers.put(field, StandardAnalyzer.class.getSimpleName());
}
}
}
代码示例来源:origin: Graylog2/graylog2-server
private Map<String, String> prefixElements(final String prefix, final Map<String, String> elements) {
if (elements == null || elements.isEmpty()) {
return Collections.emptyMap();
}
final Map<String, String> prefixedMap = new HashMap<>(elements.size());
for (Map.Entry<String, String> entry : elements.entrySet()) {
prefixedMap.put(prefix.trim() + "_" + entry.getKey(), entry.getValue());
}
return prefixedMap;
}
}
代码示例来源:origin: eclipse-vertx/vert.x
public X509KeyManager getKeyMgr(String serverName) {
X509KeyManager mgr = mgrMap.get(serverName);
if (mgr == null && !wildcardMgrMap.isEmpty()) {
int index = serverName.indexOf('.') + 1;
if (index > 0) {
String s = serverName.substring(index);
mgr = wildcardMgrMap.get(s);
}
}
return mgr;
}
代码示例来源:origin: bumptech/glide
@Override
public String toString() {
StringBuilder sb =
new StringBuilder()
.append("SizeConfigStrategy{groupedMap=")
.append(groupedMap)
.append(", sortedSizes=(");
for (Map.Entry<Bitmap.Config, NavigableMap<Integer, Integer>> entry : sortedSizes.entrySet()) {
sb.append(entry.getKey()).append('[').append(entry.getValue()).append("], ");
}
if (!sortedSizes.isEmpty()) {
sb.replace(sb.length() - 2, sb.length(), "");
}
return sb.append(")}").toString();
}
代码示例来源:origin: square/okhttp
/**
* Attaches {@code tag} to the request using {@code type} as a key. Tags can be read from a
* request using {@link Request#tag}. Use null to remove any existing tag assigned for {@code
* type}.
*
* <p>Use this API to attach timing, debugging, or other application data to a request so that
* you may read it in interceptors, event listeners, or callbacks.
*/
public <T> Builder tag(Class<? super T> type, @Nullable T tag) {
if (type == null) throw new NullPointerException("type == null");
if (tag == null) {
tags.remove(type);
} else {
if (tags.isEmpty()) tags = new LinkedHashMap<>();
tags.put(type, type.cast(tag));
}
return this;
}
内容来源于网络,如有侵权,请联系作者删除!