/** * Creates a mutable {@link HashMap} instance containing the given initial entries. Repeated occurrences of a keys * will cause an {@link IllegalArgumentException}. * * @param initial * the entries that should be contained in the map. May not be <code>null</code> but may contain * <code>null</code> keys or values. * @return a new {@link HashMap} containing those elements * @throws IllegalArgumentException * if duplicate keys are contained the {@code initial} entries. */ @Pure public static <K, V> HashMap<K, V> newHashMap(Pair<? extends K, ? extends V>... initial) { HashMap<K, V> result = Maps.newHashMapWithExpectedSize(initial.length); putAll(result, initial); return result; }
/** * Creates a mutable {@link LinkedHashMap} instance containing the given initial entries. Repeated occurrences of a * keys will cause an {@link IllegalArgumentException}. * * @param initial * the entries that should be contained in the map. May not be <code>null</code> but may contain * <code>null</code> keys or values. * @return a new {@link LinkedHashMap} containing those elements * @throws IllegalArgumentException * if duplicate keys are contained the {@code initial} entries. */ @Pure public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(Pair<? extends K, ? extends V>... initial) { LinkedHashMap<K, V> result = new LinkedHashMap<K, V>(initial.length); putAll(result, initial); return result; }
/** * Creates a mutable {@link TreeMap} instance containing the given initial entries. Repeated occurrences of a keys * will cause an {@link IllegalArgumentException}. * * @param initial * the entries that should be contained in the map. May not be <code>null</code> but may contain * <code>null</code> keys or values. * @param comparator * the comparator that should be used. May be <code>null</code> which indicates that the natural ordering * of the keys should be used. * @return a new {@link TreeMap} containing those elements * @throws IllegalArgumentException * if duplicate keys are contained the {@code initial} entries. */ @SafeVarargs @Pure public static <K, V> TreeMap<K, V> newTreeMap(Comparator<? super K> comparator, Pair<? extends K, ? extends V>... initial) { TreeMap<K, V> result = new TreeMap<K, V>(comparator); putAll(result, initial); return result; }
/** * Creates a mutable {@link TreeMap} instance containing the given initial entries. Repeated occurrences of a keys * will cause an {@link IllegalArgumentException}. * * @param initial * the entries that should be contained in the map. May not be <code>null</code> but may contain * <code>null</code> keys or values. * @param comparator * the comparator that should be used. May be <code>null</code> which indicates that the natural ordering * of the keys should be used. * @return a new {@link TreeMap} containing those elements * @throws IllegalArgumentException * if duplicate keys are contained the {@code initial} entries. */ @Pure public static <K, V> TreeMap<K, V> newTreeMap(Comparator<? super K> comparator, Pair<? extends K, ? extends V>... initial) { TreeMap<K, V> result = Maps.newTreeMap(comparator); putAll(result, initial); return result; }
/** * Creates a mutable {@link LinkedHashMap} instance containing the given initial entries. Repeated occurrences of a * keys will cause an {@link IllegalArgumentException}. * * @param initial * the entries that should be contained in the map. May not be <code>null</code> but may contain * <code>null</code> keys or values. * @return a new {@link LinkedHashMap} containing those elements * @throws IllegalArgumentException * if duplicate keys are contained the {@code initial} entries. */ @SafeVarargs @Pure public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(Pair<? extends K, ? extends V>... initial) { if (initial.length > 0) { LinkedHashMap<K, V> result = new LinkedHashMap<K, V>(capacity(initial.length)); putAll(result, initial); return result; } return newLinkedHashMap(); }
/** * Creates a mutable {@link HashMap} instance containing the given initial entries. Repeated occurrences of a keys * will cause an {@link IllegalArgumentException}. * * @param initial * the entries that should be contained in the map. May not be <code>null</code> but may contain * <code>null</code> keys or values. * @return a new {@link HashMap} containing those elements * @throws IllegalArgumentException * if duplicate keys are contained the {@code initial} entries. */ @SafeVarargs @Pure public static <K, V> HashMap<K, V> newHashMap(Pair<? extends K, ? extends V>... initial) { if (initial.length > 0) { HashMap<K, V> result = new HashMap<K, V>(capacity(initial.length)); putAll(result, initial); return result; } return newHashMap(); }