java.util.EnumMap#clear ( )源码实例Demo

下面列出了java.util.EnumMap#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: EnumMapTest.java
@SuppressWarnings({ "unchecked", "boxing" })
public void test_clear() {
    EnumMap enumSizeMap = new EnumMap(Size.class);
    enumSizeMap.put(Size.Small, 1);
    enumSizeMap.clear();
    assertNull("Failed to clear all elements", enumSizeMap.get(Size.Small));
}
 
源代码2 项目: spring-analysis-note   文件: CollectionFactory.java
/**
 * Create the most approximate map for the given map.
 * <p><strong>Warning</strong>: Since the parameterized type {@code K} is
 * not bound to the type of keys contained in the supplied {@code map},
 * type safety cannot be guaranteed if the supplied {@code map} is an
 * {@link EnumMap}. In such scenarios, the caller is responsible for
 * ensuring that the key type in the supplied {@code map} is an enum type
 * matching type {@code K}. As an alternative, the caller may wish to
 * treat the return value as a raw map or map keyed by {@link Object}.
 * @param map the original map object, potentially {@code null}
 * @param capacity the initial capacity
 * @return a new, empty map instance
 * @see #isApproximableMapType
 * @see java.util.EnumMap
 * @see java.util.TreeMap
 * @see java.util.LinkedHashMap
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public static <K, V> Map<K, V> createApproximateMap(@Nullable Object map, int capacity) {
	if (map instanceof EnumMap) {
		EnumMap enumMap = new EnumMap((EnumMap) map);
		enumMap.clear();
		return enumMap;
	}
	else if (map instanceof SortedMap) {
		return new TreeMap<>(((SortedMap<K, V>) map).comparator());
	}
	else {
		return new LinkedHashMap<>(capacity);
	}
}
 
源代码3 项目: java-technology-stack   文件: CollectionFactory.java
/**
 * Create the most approximate map for the given map.
 * <p><strong>Warning</strong>: Since the parameterized type {@code K} is
 * not bound to the type of keys contained in the supplied {@code map},
 * type safety cannot be guaranteed if the supplied {@code map} is an
 * {@link EnumMap}. In such scenarios, the caller is responsible for
 * ensuring that the key type in the supplied {@code map} is an enum type
 * matching type {@code K}. As an alternative, the caller may wish to
 * treat the return value as a raw map or map keyed by {@link Object}.
 * @param map the original map object, potentially {@code null}
 * @param capacity the initial capacity
 * @return a new, empty map instance
 * @see #isApproximableMapType
 * @see java.util.EnumMap
 * @see java.util.TreeMap
 * @see java.util.LinkedHashMap
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public static <K, V> Map<K, V> createApproximateMap(@Nullable Object map, int capacity) {
	if (map instanceof EnumMap) {
		EnumMap enumMap = new EnumMap((EnumMap) map);
		enumMap.clear();
		return enumMap;
	}
	else if (map instanceof SortedMap) {
		return new TreeMap<>(((SortedMap<K, V>) map).comparator());
	}
	else {
		return new LinkedHashMap<>(capacity);
	}
}
 
源代码4 项目: lams   文件: CollectionFactory.java
/**
 * Create the most approximate map for the given map.
 * <p><strong>Warning</strong>: Since the parameterized type {@code K} is
 * not bound to the type of keys contained in the supplied {@code map},
 * type safety cannot be guaranteed if the supplied {@code map} is an
 * {@link EnumMap}. In such scenarios, the caller is responsible for
 * ensuring that the key type in the supplied {@code map} is an enum type
 * matching type {@code K}. As an alternative, the caller may wish to
 * treat the return value as a raw map or map keyed by {@link Object}.
 * @param map the original map object, potentially {@code null}
 * @param capacity the initial capacity
 * @return a new, empty map instance
 * @see #isApproximableMapType
 * @see java.util.EnumMap
 * @see java.util.TreeMap
 * @see java.util.LinkedHashMap
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public static <K, V> Map<K, V> createApproximateMap(Object map, int capacity) {
	if (map instanceof EnumMap) {
		EnumMap enumMap = new EnumMap((EnumMap) map);
		enumMap.clear();
		return enumMap;
	}
	else if (map instanceof SortedMap) {
		return new TreeMap<K, V>(((SortedMap<K, V>) map).comparator());
	}
	else {
		return new LinkedHashMap<K, V>(capacity);
	}
}
 
源代码5 项目: spring4-understanding   文件: CollectionFactory.java
/**
 * Create the most approximate map for the given map.
 * <p><strong>Warning</strong>: Since the parameterized type {@code K} is
 * not bound to the type of keys contained in the supplied {@code map},
 * type safety cannot be guaranteed if the supplied {@code map} is an
 * {@link EnumMap}. In such scenarios, the caller is responsible for
 * ensuring that the key type in the supplied {@code map} is an enum type
 * matching type {@code K}. As an alternative, the caller may wish to
 * treat the return value as a raw map or map keyed by {@link Object}.
 * @param map the original map object, potentially {@code null}
 * @param capacity the initial capacity
 * @return a new, empty map instance
 * @see #isApproximableMapType
 * @see java.util.EnumMap
 * @see java.util.TreeMap
 * @see java.util.LinkedHashMap
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public static <K, V> Map<K, V> createApproximateMap(Object map, int capacity) {
	if (map instanceof EnumMap) {
		EnumMap enumMap = new EnumMap((EnumMap) map);
		enumMap.clear();
		return enumMap;
	}
	else if (map instanceof SortedMap) {
		return new TreeMap<K, V>(((SortedMap<K, V>) map).comparator());
	}
	else {
		return new LinkedHashMap<K, V>(capacity);
	}
}