1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| Map map = Maps.newHashMap(); Map map = Maps.newHashMap(Map<? extends K, ? extends V> map); Map map = Maps.newHashMapWithExpectedSize(int expectedSize); Map map = Maps.newConcurrentMap();
enum DEPARTMENT { UI, DEVELOP, TEST; } EnumMap<DEPARTMENT, Map<String,String>> map = Maps.newEnumMap(DEPARTMENT.class); map.put(DEPARTMENT.UI, Maps.toMap(Arrays.asList("ui-1", "ui-2"), k -> k + " info")); map.put(DEPARTMENT.DEVELOP, Maps.toMap(Arrays.asList("dev-1", "dev-2"), k -> k + " info")); map.put(DEPARTMENT.TEST, Maps.toMap(Arrays.asList("test-1", "test-2"), k -> k + " info"));
Maps.immutableEnumMap(Map<K, ? extends V> map);
LinkedHashMap map = Maps.newLinkedHashMap(); LinkedHashMap map = Maps.newLinkedHashMap(Map<? extends K, ? extends V> map); LinkedHashMap map = Maps.newLinkedHashMapWithExpectedSize(int expectedSize);
TreeMap treeMap = Maps.newTreeMap(); TreeMap treeMap = Maps.newTreeMap(SortedMap<K, ? extends V> map); TreeMap treeMap = Maps.newTreeMap(@Nullable Comparator<C> comparator);
Map<K, V> map = Maps.asMap(Set<K> set, Function<? super K, V> function); SortedMap<K, V> map = Maps.asMap(SortedSet<K> set, Function<? super K, V> function); NavigableMap<K, V> map = Maps.asMap(NavigableSet<K> set, Function<? super K, V> function); Map<Integer, Integer> map = Maps.asMap(Sets.newLinkedHashSet(Ints.asList(4, 2, 3)), i -> i * 2);
ImmutableMap map = Maps.toMap(Iterable<K> keys, Function<? super K, V> valueFunction); ImmutableMap map = Maps.toMap(Iterator<K> keys, Function<? super K, V> valueFunction) ImmutableMap<Integer, String> map = Maps.toMap(Ints.asList(1, 2, 3), k -> k + "0");
ImmutableMap map = Maps.uniqueIndex(Iterable<V> values, Function<? super V, K> keyFunction); ImmutableMap map = Maps.uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction); ImmutableMap<String, Integer> map = Maps.uniqueIndex(Ints.asList(1, 2, 3), i -> "0" + i);
ImmutableMap<String, Integer> leftMap = ImmutableMap.of("a", 1, "b", 2, "c",3); ImmutableMap<String, Integer> rightMap = ImmutableMap.of("a", 2, "b", 2, "d",4); MapDifference<String, Integer> diff = Maps.difference(leftMap, rightMap); Map<String, Integer> onlyOnLeft = diff.entriesOnlyOnLeft(); Map<String, Integer> onlyOnRight = diff.entriesOnlyOnRight(); Map<String, Integer> inCommon = diff.entriesInCommon(); Map<String, ValueDifference<Integer>> differing = diff.entriesDiffering();
Map<K, V> filterKeys(Map<K, V> unfiltered, Predicate<? super K> keyPredicate); SortedMap<K, V> filterKeys(SortedMap<K, V> unfiltered, Predicate<? super K> keyPredicate); NavigableMap<K, V> filterKeys(NavigableMap<K, V> unfiltered, Predicate<? super K> keyPredicate); BiMap<K, V> filterKeys(BiMap<K, V> unfiltered, Predicate<? super K> keyPredicate); Maps.filterKeys(ImmutableMap.of("a", 1, "b", 2, "c", 3), key -> !key.equals("a"));
Map<K, V> filterValues(Map<K, V> unfiltered, Predicate<? super V> valuePredicate); SortedMap<K, V> filterValues(SortedMap<K, V> unfiltered, Predicate<? super V> valuePredicate); NavigableMap<K, V> filterValues(NavigableMap<K, V> unfiltered, Predicate<? super V> valuePredicate); BiMap<K, V> filterValues(BiMap<K, V> unfiltered, Predicate<? super V> valuePredicate) Maps.filterValues(ImmutableMap.of("a", 1, "b", 2, "c", 3), val -> val > 1);
Map<K, V> filterEntries(Map<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate); SortedMap<K, V> filterEntries(SortedMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate); NavigableMap<K, V> filterEntries(NavigableMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate); BiMap<K, V> filterEntries(BiMap<K, V> unfiltered, Predicate<? super Entry<K, V>> entryPredicate); Maps.filterEntries(ImmutableMap.of("a", 1, "b", 2, "c", 3), entry -> !entry.getKey().equals("a") && entry.getValue() > 2);
Map<K, V2> transformEntries(Map<K, V1> fromMap, Maps.EntryTransformer<? super K, ? super V1, V2> transformer); SortedMap<K, V2> transformEntries(SortedMap<K, V1> fromMap, Maps.EntryTransformer<? super K, ? super V1, V2> transformer); NavigableMap<K, V2> transformEntries(NavigableMap<K, V1> fromMap, Maps.EntryTransformer<? super K, ? super V1, V2> transformer); Map<Integer, Integer> fromMap = Maps.asMap(Sets.newLinkedHashSet(Ints.asList(4, 2, 3)), i -> i * 2); Map<Integer, String> map = Maps.transformEntries(fromMap, (k, v) -> k + ":" + v);
Map<K, V2> transformValues(Map<K, V1> fromMap, Function<? super V1, V2> function); SortedMap<K, V2> transformValues(SortedMap<K, V1> fromMap, Function<? super V1, V2> function); NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap, Function<? super V1, V2> function); Map<Integer, Integer> fromMap = Maps.asMap(Sets.newLinkedHashSet(Ints.asList(4, 2, 3)), i -> i * 2); Map<Integer, String> map = Maps.transformValues(fromMap, k -> k + "0");
|