@Override protected Map<String, String> create(Entry<String, String>[] entries) { Map<String, String> map = populate(new HashMap<String, String>(), entries); return Collections.checkedMap(map, String.class, String.class); } })
LinkedProperties() { this(Collections.checkedMap(new LinkedHashMap<String, String>(), String.class, String.class)); }
@SuppressWarnings("CloneDoesntCallSuperClone") public LinkedProperties clone() { return new LinkedProperties(Collections.checkedMap(new LinkedHashMap<String, String>(realMap), String.class, String.class)); } }
classes.add(Collections.checkedList(randomAccessList, Void.class).getClass()); classes.add(Collections.checkedList(nonRandomAccessList, Void.class).getClass()); classes.add(Collections.checkedMap(Collections.emptyMap(), Void.class, Void.class).getClass()); classes.add(Collections.checkedNavigableMap(Collections.emptyNavigableMap(), Void.class, Void.class).getClass()); classes.add(Collections.checkedNavigableSet(Collections.emptyNavigableSet(), Void.class).getClass());
PojoWithObjectMapFields fill() { TreeMap<String, String> tm = new TreeMap<String, String>(); tm.put("foo", "bar"); EnumMap<GuitarPickup, Size> em = new EnumMap<GuitarPickup, Size>( GuitarPickup.class); em.put(GuitarPickup.CONTACT, Size.SMALL); emptyMap = Collections.emptyMap(); singletonMap = Collections.singletonMap("key", "value"); unmodifiableMap = Collections.unmodifiableMap(Collections .emptyMap()); unmodifiableSortedMap = Collections.unmodifiableSortedMap(tm); synchronizedMap = Collections.synchronizedMap(em); synchronizedSortedMap = Collections.synchronizedSortedMap(tm); checkedMap = Collections.checkedMap(em, GuitarPickup.class, Size.class); checkedSortedMap = Collections.checkedSortedMap(tm, String.class, String.class); return this; }
@Override public Dollar.MapWrapper<K, V> checked(Class<K> requiredKeyClass, Class<V> requiredValueClass) { map = Collections.checkedMap(map, requiredKeyClass, requiredValueClass); return this; }
@Override protected Map<String, String> create(Entry<String, String>[] entries) { Map<String, String> map = populate(new HashMap<String, String>(), entries); return Collections.checkedMap(map, String.class, String.class); } })
private Map<String, ?> map; public <V> void createMap(Class<V> clazz) { map = Collections.checkedMap(new HashMap<String, V>(), String.class, clazz); }
/** * Only Scope and derivatives may create a Scope object. * * @param parentScope null if called by the SymbolScopeRoot constructor. */ @SuppressWarnings({"unchecked", "rawtypes"}) private TreeParserSymbolScope(TreeParserSymbolScope parentScope) { this.parentScope = parentScope; typeMap.put(ProParserTokenTypes.VARIABLE, Collections.checkedMap((Map) variableMap, String.class, Symbol.class)); }
public static <K, V> Map<K, V> map(Class<K> key, Class<V> value) { return Collections.checkedMap(new LinkedHashMap<>(), key, value); }
/** * Only Scope and derivatives may create a Scope object. * * @param parentScope null if called by the SymbolScopeRoot constructor. */ @SuppressWarnings({"unchecked", "rawtypes"}) private TreeParserSymbolScope(TreeParserSymbolScope parentScope) { this.parentScope = parentScope; typeMap.put(ProParserTokenTypes.VARIABLE, Collections.checkedMap((Map) variableMap, String.class, Symbol.class)); }
Class<String> type = String.class; Map<String, String> hashMap = new HashMap<>(); Map<String, String> map = Collections.checkedMap(hashMap, type, type); Map rawType = map; // pre-Java 1.5 code knows nothing about generics rawType.put(1, 2); // throws ClassCastException at runtime
Map<String, Object> map = new HashMap<String, Object>(); Map<String, String> newMap = new HashMap<String, String>(); @SuppressWarnings("unchecked") Map<String, Object> intermediate = (Map)Collections.checkedMap(newMap, String.class, String.class); intermediate.putAll(map);
/** @return a Map of ObjectNames from a Map whose values are AMX. */ public static Map<String, ObjectName> toObjectNameMap(final Map<String, ? extends AMXProxy> amxMap) { final Map<String, ObjectName> m = new HashMap<String, ObjectName>(); for (final String key : amxMap.keySet()) { final AMXProxy value = amxMap.get(key); m.put(key, value.objectName()); } return (Collections.checkedMap(m, String.class, ObjectName.class)); }
/** Create a checked Map<String,String>, first verifying that all keys and values are in fact String. @param m the Map @throws ClassCastException */ public static <K, V> Map<K, V> checkedMap(final Map<?, ?> m, final Class<K> keyClass, final Class<V> valueClass) { final Map<K, V> cm = checkMap(m, keyClass, valueClass); return Collections.checkedMap(cm, keyClass, valueClass); }
/** @return a Map of ObjectNames from a Map whose values are AMX. */ public static Map<String, ObjectName> toObjectNameMap(final Map<String, ? extends AMXProxy> amxMap) { final Map<String, ObjectName> m = new HashMap<String, ObjectName>(); for (final Map.Entry<String,? extends AMXProxy> e : amxMap.entrySet()) { final AMXProxy value = e.getValue(); m.put(e.getKey(), value.objectName()); } return (Collections.checkedMap(m, String.class, ObjectName.class)); }
@SuppressWarnings("CloneDoesntCallSuperClone") public LinkedProperties clone() { return new LinkedProperties(Collections.checkedMap(new LinkedHashMap<String, String>(realMap), String.class, String.class)); } }
@SuppressWarnings("CloneDoesntCallSuperClone") public LinkedProperties clone() { return new LinkedProperties(Collections.checkedMap(new LinkedHashMap<String, String>(realMap), String.class, String.class)); } }
/** Create a checked Map<String,String>, first verifying that all keys and values are in fact String. @param m the Map @throws ClassCastException */ public static <K, V> Map<K, V> checkedMap(final Map<?, ?> m, final Class<K> keyClass, final Class<V> valueClass) { final Map<K, V> cm = checkMap(m, keyClass, valueClass); return Collections.checkedMap(cm, keyClass, valueClass); }
@SuppressWarnings("CloneDoesntCallSuperClone") public LinkedProperties clone() { return new LinkedProperties(Collections.checkedMap(new LinkedHashMap<String, String>(realMap), String.class, String.class)); } }