Java Code Examples for java.util.EnumMap#clear()

The following examples show how to use java.util.EnumMap#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumMapTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 2
Source File: CollectionFactory.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * 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);
	}
}
 
Example 3
Source File: CollectionFactory.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * 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);
	}
}
 
Example 4
Source File: CollectionFactory.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
	}
}
 
Example 5
Source File: CollectionFactory.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
	}
}