本文整理了Java中java.util.Map.clear()
方法的一些代码示例,展示了Map.clear()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.clear()
方法的具体详情如下:
包路径:java.util.Map
类名称:Map
方法名:clear
[英]Removes all elements from this Map, leaving it empty.
[中]删除此映射中的所有元素,将其保留为空。
代码示例来源:origin: spring-projects/spring-framework
/**
* Close the bundle View factories on context shutdown.
*/
@Override
public void destroy() throws BeansException {
for (ConfigurableApplicationContext factory : this.bundleCache.values()) {
factory.close();
}
this.localeCache.clear();
this.bundleCache.clear();
}
代码示例来源:origin: log4j/log4j
public static void resetLogLevelColorMap() {
// empty the map
_logLevelColorMap.clear();
// repopulate map and reset text color black
for (int i = 0; i < _allDefaultLevels.length; i++) {
_logLevelColorMap.put(_allDefaultLevels[i], Color.black);
}
}
代码示例来源:origin: apache/kafka
private void deepCopy(Map<String, List<TopicPartition>> source, Map<String, List<TopicPartition>> dest) {
dest.clear();
for (Entry<String, List<TopicPartition>> entry: source.entrySet())
dest.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@SuppressWarnings({"unchecked", "rawtypes"})
protected void visitMap(Map<?, ?> mapVal) {
Map newContent = new LinkedHashMap();
boolean entriesModified = false;
for (Map.Entry entry : mapVal.entrySet()) {
Object key = entry.getKey();
int keyHash = (key != null ? key.hashCode() : 0);
Object newKey = resolveValue(key);
int newKeyHash = (newKey != null ? newKey.hashCode() : 0);
Object val = entry.getValue();
Object newVal = resolveValue(val);
newContent.put(newKey, newVal);
entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash);
}
if (entriesModified) {
mapVal.clear();
mapVal.putAll(newContent);
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Resets the mount table state.
*/
public void reset() {
MountInfo mountInfo = mMountTable.get(ROOT);
mMountTable.clear();
if (mountInfo != null) {
mMountTable.put(ROOT, mountInfo);
}
}
}
代码示例来源:origin: apache/storm
public Map<String, List<FixedTuple>> getAndClearResults() {
Map<String, List<FixedTuple>> ret = new HashMap<>(emitted_tuples.get(_name));
emitted_tuples.get(_name).clear();
return ret;
}
代码示例来源:origin: apache/incubator-dubbo
public static void resetExtensionLoader(Class type) {
ExtensionLoader loader = EXTENSION_LOADERS.get(type);
if (loader != null) {
// Remove all instances associated with this loader as well
Map<String, Class<?>> classes = loader.getExtensionClasses();
for (Map.Entry<String, Class<?>> entry : classes.entrySet()) {
EXTENSION_INSTANCES.remove(entry.getValue());
}
classes.clear();
EXTENSION_LOADERS.remove(type);
}
}
代码示例来源:origin: google/guava
public void testStandardEntrySet() throws InvocationTargetException {
@SuppressWarnings("unchecked")
final Map<String, Boolean> map = mock(Map.class);
Map<String, Boolean> forward =
new ForwardingMap<String, Boolean>() {
@Override
protected Map<String, Boolean> delegate() {
return map;
}
@Override
public Set<Entry<String, Boolean>> entrySet() {
return new StandardEntrySet() {
@Override
public Iterator<Entry<String, Boolean>> iterator() {
return Iterators.emptyIterator();
}
};
}
};
callAllPublicMethods(new TypeToken<Set<Entry<String, Boolean>>>() {}, forward.entrySet());
// These are the methods specified by StandardEntrySet
verify(map, atLeast(0)).clear();
verify(map, atLeast(0)).containsKey(anyObject());
verify(map, atLeast(0)).get(anyObject());
verify(map, atLeast(0)).isEmpty();
verify(map, atLeast(0)).remove(anyObject());
verify(map, atLeast(0)).size();
verifyNoMoreInteractions(map);
}
代码示例来源:origin: org.slf4j/slf4j-log4j12
@SuppressWarnings({ "rawtypes", "unchecked" })
public void setContextMap(Map contextMap) {
Map old = org.apache.log4j.MDC.getContext();
if (old == null) {
Iterator entrySetIterator = contextMap.entrySet().iterator();
while (entrySetIterator.hasNext()) {
Map.Entry mapEntry = (Map.Entry) entrySetIterator.next();
org.apache.log4j.MDC.put((String) mapEntry.getKey(), mapEntry.getValue());
}
} else {
old.clear();
old.putAll(contextMap);
}
}
}
代码示例来源:origin: google/guava
public void testStandardValues() throws InvocationTargetException {
@SuppressWarnings("unchecked")
final Map<String, Boolean> map = mock(Map.class);
Map<String, Boolean> forward =
new ForwardingMap<String, Boolean>() {
@Override
protected Map<String, Boolean> delegate() {
return map;
}
@Override
public Collection<Boolean> values() {
return new StandardValues();
}
};
callAllPublicMethods(new TypeToken<Collection<Boolean>>() {}, forward.values());
// These are the methods specified by StandardValues
verify(map, atLeast(0)).clear();
verify(map, atLeast(0)).containsValue(anyObject());
verify(map, atLeast(0)).isEmpty();
verify(map, atLeast(0)).size();
verify(map, atLeast(0)).entrySet();
verifyNoMoreInteractions(map);
}
代码示例来源:origin: google/guava
@Override
public void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) {
this.delegate.replaceAll(function);
inverse.delegate.clear();
Entry<K, V> broken = null;
Iterator<Entry<K, V>> itr = this.delegate.entrySet().iterator();
while (itr.hasNext()) {
Entry<K, V> entry = itr.next();
K k = entry.getKey();
V v = entry.getValue();
K conflict = inverse.delegate.putIfAbsent(v, k);
if (conflict != null) {
broken = entry;
// We're definitely going to throw, but we'll try to keep the BiMap in an internally
// consistent state by removing the bad entry.
itr.remove();
}
}
if (broken != null) {
throw new IllegalArgumentException("value already present: " + broken.getValue());
}
}
代码示例来源:origin: apache/ignite
/**
* @param cmpId component ID.
*/
private void reinitNodeSpecData(int cmpId) {
nodeSpecificData.clear();
for (Map.Entry<UUID, Map<Integer, Serializable>> e : DiscoveryDataBag.this.nodeSpecificData.entrySet()) {
if (e.getValue() != null && e.getValue().containsKey(cmpId))
nodeSpecificData.put(e.getKey(), e.getValue().get(cmpId));
}
}
}
代码示例来源:origin: rest-assured/rest-assured
/**
* Set the default headers to add to all requests made by this builder
* instance. These values will replace any previously set default headers.
*
* @param headers map of header names & values.
*/
public void setHeaders(Map<?, ?> headers) {
this.defaultRequestHeaders.clear();
if (headers == null) return;
for (Object key : headers.keySet()) {
Object val = headers.get(key);
if (val == null) continue;
this.defaultRequestHeaders.put(key.toString(), val.toString());
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Configure path prefixes to apply to controller methods.
* <p>Prefixes are used to enrich the mappings of every {@code @RequestMapping}
* method whose controller type is matched by a corresponding
* {@code Predicate} in the map. The prefix for the first matching predicate
* is used, assuming the input map has predictable order.
* <p>Consider using {@link org.springframework.web.method.HandlerTypePredicate
* HandlerTypePredicate} to group controllers.
* @param prefixes a map with path prefixes as key
* @since 5.1
* @see org.springframework.web.method.HandlerTypePredicate
*/
public void setPathPrefixes(Map<String, Predicate<Class<?>>> prefixes) {
this.pathPrefixes.clear();
prefixes.entrySet().stream()
.filter(entry -> StringUtils.hasText(entry.getKey()))
.forEach(entry -> this.pathPrefixes.put(entry.getKey(), entry.getValue()));
}
代码示例来源:origin: jenkinsci/jenkins
private static ProcessBuilder environment(ProcessBuilder pb, String[] env) {
if(env!=null) {
Map<String, String> m = pb.environment();
m.clear();
for (String e : env) {
int idx = e.indexOf('=');
m.put(e.substring(0,idx),e.substring(idx+1,e.length()));
}
}
return pb;
}
代码示例来源:origin: alibaba/jstorm
public Map<String, List<FixedTuple>> getAndClearResults() {
Map<String, List<FixedTuple>> ret = new HashMap<String, List<FixedTuple>>(emitted_tuples.get(_name));
emitted_tuples.get(_name).clear();
return ret;
}
代码示例来源:origin: apache/incubator-dubbo
public static void resetExtensionLoader(Class type) {
ExtensionLoader loader = EXTENSION_LOADERS.get(type);
if (loader != null) {
// Remove all instances associated with this loader as well
Map<String, Class<?>> classes = loader.getExtensionClasses();
for (Map.Entry<String, Class<?>> entry : classes.entrySet()) {
EXTENSION_INSTANCES.remove(entry.getValue());
}
classes.clear();
EXTENSION_LOADERS.remove(type);
}
}
代码示例来源:origin: google/guava
@Override
public void clear() {
// Clear each collection, to make previously returned collections empty.
for (Collection<V> collection : map.values()) {
collection.clear();
}
map.clear();
totalSize = 0;
}
代码示例来源:origin: apache/hive
public Map<String, List<ExprNodeDesc>> getResidualPredicates(boolean clear) {
Map<String, List<ExprNodeDesc>> oldExprs = new HashMap<String, List<ExprNodeDesc>>();
for (Map.Entry<String, List<ExprNodeDesc>> entry : nonFinalPreds.entrySet()) {
List<ExprNodeDesc> converted = new ArrayList<ExprNodeDesc>();
for (ExprNodeDesc newExpr : entry.getValue()) {
converted.add(newToOldExprMap.get(newExpr));
}
oldExprs.put(entry.getKey(), converted);
}
if (clear) {
nonFinalPreds.clear();
}
return oldExprs;
}
代码示例来源:origin: stackoverflow.com
public static <K,R,S,T> Map<K, R> zipWith(Function2<R,S,T> fn,
Map<K, S> m1, Map<K, T> m2, Map<K, R> results){
Set<K> keySet = new HashSet<K>();
keySet.addAll(m1.keySet());
keySet.addAll(m2.keySet());
results.clear();
for (K key : keySet) {
results.put(key, fn.eval(m1.get(key), m2.get(key)));
}
return results;
}
内容来源于网络,如有侵权,请联系作者删除!