@Override Map<K, Collection<V2>> createAsMap() { return Maps.transformEntries( fromMultimap.asMap(), new EntryTransformer<K, Collection<V1>, Collection<V2>>() { @Override public Collection<V2> transformEntry(K key, Collection<V1> value) { return transform(key, value); } }); }
private static Map<String, Object> getSerializableClientProperties(final Map<String, Object> clientProperties) { return Maps.transformEntries( clientProperties, new Maps.EntryTransformer<String, Object, Object>() { @Override public Object transformEntry(String key, Object value) { if (value instanceof LongString) { return value.toString(); } return value; } } ); }
@Override public SortedMap<K, V2> tailMap(K fromKey) { return transformEntries(fromMap().tailMap(fromKey), transformer); } }
@Override public SortedMap<K, V2> headMap(K toKey) { return transformEntries(fromMap().headMap(toKey), transformer); }
@Override public SortedMap<K, V2> subMap(K fromKey, K toKey) { return transformEntries(fromMap().subMap(fromKey, toKey), transformer); }
@Override Map<K, Collection<V2>> createAsMap() { return Maps.transformEntries( fromMultimap.asMap(), new EntryTransformer<K, Collection<V1>, Collection<V2>>() { @Override public Collection<V2> transformEntry(K key, Collection<V1> value) { return transform(key, value); } }); }
@Override public NavigableMap<K, V2> subMap( K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { return transformEntries( fromMap().subMap(fromKey, fromInclusive, toKey, toInclusive), transformer); }
return transformEntries(fromMap, asEntryTransformer(function));
@Override public NavigableMap<K, V2> headMap(K toKey, boolean inclusive) { return transformEntries(fromMap().headMap(toKey, inclusive), transformer); }
@Override public NavigableMap<K, V2> descendingMap() { return transformEntries(fromMap().descendingMap(), transformer); }
@Override public NavigableMap<K, V2> tailMap(K fromKey, boolean inclusive) { return transformEntries(fromMap().tailMap(fromKey, inclusive), transformer); }
return transformEntries(fromMap, asEntryTransformer(function));
@Override protected Map<String, String> create(Entry<String, String>[] entries) { Map<String, String> map = Maps.newLinkedHashMap(); for (Entry<String, String> entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); } })
@Override protected NavigableMap<String, String> create(Entry<String, String>[] entries) { NavigableMap<String, String> map = new SafeTreeMap<>(); for (Entry<String, String> entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); } })
public void testTransformEntriesExample() { Map<String, Boolean> options = ImmutableMap.of("verbose", true, "sort", false); EntryTransformer<String, Boolean, String> flagPrefixer = new EntryTransformer<String, Boolean, String>() { @Override public String transformEntry(String key, Boolean value) { return value ? key : "no" + key; } }; Map<String, String> transformed = transformEntries(options, flagPrefixer); assertEquals("{verbose=verbose, sort=nosort}", transformed.toString()); }
@Override protected SortedMap<String, String> create(Entry<String, String>[] entries) { SortedMap<String, String> map = new NonNavigableSortedMap(); for (Entry<String, String> entry : entries) { map.put(entry.getKey(), encode(entry.getValue())); } return Maps.transformEntries(map, DECODE_ENTRY_TRANSFORMER); } })
public void testTransformEntries() { Map<String, String> map = ImmutableMap.of("a", "4", "b", "9"); EntryTransformer<String, String, String> concat = new EntryTransformer<String, String, String>() { @Override public String transformEntry(String key, String value) { return key + value; } }; Map<String, String> transformed = transformEntries(map, concat); assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed); }
@Override public Object compute(Map<String, Object> values) { // Maps.transformEntries is lazy, will only finalize values we actually read. final Map<String, Object> finalizedValues = Maps.transformEntries( values, (String k, Object v) -> { final Function<Object, Object> finalizer = finalizers.get(k); return finalizer != null ? finalizer.apply(v) : v; } ); return parsed.eval(Parser.withMap(finalizedValues)).value(); }
@GwtIncompatible // NavigableMap public void testNavigableMapTransformEntries() { NavigableMap<String, String> map = ImmutableSortedMap.of("a", "4", "b", "9"); EntryTransformer<String, String, String> concat = new EntryTransformer<String, String, String>() { @Override public String transformEntry(String key, String value) { return key + value; } }; NavigableMap<String, String> transformed = transformEntries(map, concat); assertEquals(ImmutableSortedMap.of("a", "a4", "b", "b9"), transformed); }
public void testSortedMapTransformEntries() { SortedMap<String, String> map = sortedNotNavigable(ImmutableSortedMap.of("a", "4", "b", "9")); EntryTransformer<String, String, String> concat = new EntryTransformer<String, String, String>() { @Override public String transformEntry(String key, String value) { return key + value; } }; SortedMap<String, String> transformed = transformEntries(map, concat); /* * We'd like to sanity check that we didn't get a NavigableMap out, but we * can't easily do so while maintaining GWT compatibility. */ assertEquals(ImmutableSortedMap.of("a", "a4", "b", "b9"), transformed); }