Skip to content

Commit

Permalink
Never return a (Sorted|Navigable|Bi)(Map|Set) from the plain (Map|Set…
Browse files Browse the repository at this point in the history
…) overloads.

Prior to this CL, the plain overloads performed instanceof checks, delegating to the (Sorted|Navigable|Bi) versions when possible.

The old behavior is probably The Right Thing, but it hinders Proguarding.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=116128191
  • Loading branch information
cpovirk committed Mar 2, 2016
1 parent 2b384af commit 2d97fd8
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 271 deletions.
Expand Up @@ -16,20 +16,13 @@

package com.google.common.collect;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Maps.EntryTransformer;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;

/**
* Minimal GWT emulation of {@code com.google.common.collect.Platform}.
Expand Down Expand Up @@ -61,27 +54,6 @@ static MapMaker tryWeakKeys(MapMaker mapMaker) {
return mapMaker;
}

static <K, V1, V2> SortedMap<K, V2> mapsTransformEntriesSortedMap(
SortedMap<K, V1> fromMap,
EntryTransformer<? super K, ? super V1, V2> transformer) {
return Maps.transformEntriesIgnoreNavigable(fromMap, transformer);
}

static <K, V> SortedMap<K, V> mapsAsMapSortedSet(
SortedSet<K> set, Function<? super K, V> function) {
return Maps.asMapSortedIgnoreNavigable(set, function);
}

static <E> SortedSet<E> setsFilterSortedSet(
SortedSet<E> unfiltered, Predicate<? super E> predicate) {
return Sets.filterSortedIgnoreNavigable(unfiltered, predicate);
}

static <K, V> SortedMap<K, V> mapsFilterSortedMap(
SortedMap<K, V> unfiltered, Predicate<? super Map.Entry<K, V>> predicate) {
return Maps.filterSortedIgnoreNavigable(unfiltered, predicate);
}

static <E> Deque<E> newFastestDeque(int ignored) {
return new LinkedList<E>();
}
Expand Down
Expand Up @@ -303,11 +303,6 @@ public void testTransformSingletonMapEquality() throws Exception {
testCase.testTransformSingletonMapEquality();
}

public void testTransformValuesSecretlySortedMap() throws Exception {
com.google.common.collect.MapsSortedTransformValuesTest testCase = new com.google.common.collect.MapsSortedTransformValuesTest();
testCase.testTransformValuesSecretlySortedMap();
}

public void testValues() throws Exception {
com.google.common.collect.MapsSortedTransformValuesTest testCase = new com.google.common.collect.MapsSortedTransformValuesTest();
testCase.testValues();
Expand Down
45 changes: 0 additions & 45 deletions guava-gwt/test/com/google/common/collect/MapsTest_gwt.java
Expand Up @@ -73,11 +73,6 @@ public void testAsMapReadsThrough() throws Exception {
testCase.testAsMapReadsThrough();
}

public void testAsMapReturnsSortedMapForSortedSetInput() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapReturnsSortedMapForSortedSetInput();
}

public void testAsMapSorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testAsMapSorted();
Expand Down Expand Up @@ -328,21 +323,11 @@ public void testTransformEntriesGenerics() throws Exception {
testCase.testTransformEntriesGenerics();
}

public void testTransformEntriesSecretlySorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformEntriesSecretlySorted();
}

public void testTransformValues() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformValues();
}

public void testTransformValuesSecretlySorted() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTransformValuesSecretlySorted();
}

public void testTreeMap() throws Exception {
com.google.common.collect.MapsTest testCase = new com.google.common.collect.MapsTest();
testCase.testTreeMap();
Expand Down Expand Up @@ -403,21 +388,6 @@ public void testUnmodifiableBiMap() throws Exception {
testCase.testUnmodifiableBiMap();
}

public void testFilterEntriesIdentifiesBiMap__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilterEntriesIdentifiesBiMap();
}

public void testFilterKeysIdentifiesBiMap__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilterKeysIdentifiesBiMap();
}

public void testFilterValuesIdentifiesBiMap__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilterValuesIdentifiesBiMap();
}

public void testFilteredEntriesIllegalPut__FilteredBiMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredBiMapTest testCase = new com.google.common.collect.MapsTest.FilteredBiMapTest();
testCase.testFilteredEntriesIllegalPut();
Expand Down Expand Up @@ -473,21 +443,6 @@ public void testFilteredValuesIllegalSetValue__FilteredBiMapTest() throws Except
testCase.testFilteredValuesIllegalSetValue();
}

public void testFilterEntriesIdentifiesSortedMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilterEntriesIdentifiesSortedMap();
}

public void testFilterKeysIdentifiesSortedMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilterKeysIdentifiesSortedMap();
}

public void testFilterValuesIdentifiesSortedMap__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilterValuesIdentifiesSortedMap();
}

public void testFilteredEntriesIllegalPut__FilteredSortedMapTest() throws Exception {
com.google.common.collect.MapsTest.FilteredSortedMapTest testCase = new com.google.common.collect.MapsTest.FilteredSortedMapTest();
testCase.testFilteredEntriesIllegalPut();
Expand Down
Expand Up @@ -20,7 +20,6 @@
import com.google.common.base.Function;
import com.google.common.base.Functions;

import java.util.Map;
import java.util.SortedMap;

/**
Expand All @@ -45,10 +44,4 @@ protected SortedMap<String, String> makePopulatedMap() {
underlying.put("c", 3);
return Maps.transformValues(underlying, Functions.toStringFunction());
}

public void testTransformValuesSecretlySortedMap() {
Map<String, String> sortedMap = Maps.newTreeMap();
assertTrue(Maps.transformValues(sortedMap, Functions.<String>identity())
instanceof SortedMap);
}
}
107 changes: 0 additions & 107 deletions guava-tests/test/com/google/common/collect/MapsTest.java
Expand Up @@ -696,11 +696,6 @@ protected SortedSet<String> delegate() {
}
}

public void testAsMapReturnsSortedMapForSortedSetInput() {
Set<String> set = new NonNavigableSortedSet();
assertTrue(Maps.asMap(set, Functions.identity()) instanceof SortedMap);
}

public void testAsMapSorted() {
SortedSet<String> strings = new NonNavigableSortedSet();
Collections.addAll(strings, "one", "two", "three");
Expand Down Expand Up @@ -790,12 +785,6 @@ public void testAsMapSortedEmpty() {
assertNull(map.get("five"));
}

@GwtIncompatible // NavigableMap
public void testAsMapReturnsNavigableMapForNavigableSetInput() {
Set<String> set = Sets.newTreeSet();
assertTrue(Maps.asMap(set, Functions.identity()) instanceof NavigableMap);
}

@GwtIncompatible // NavigableMap
public void testAsMapNavigable() {
NavigableSet<String> strings =
Expand Down Expand Up @@ -1552,24 +1541,6 @@ SortedMap<String, Integer> createUnfiltered() {
return Maps.newTreeMap();
}

public void testFilterKeysIdentifiesSortedMap() {
SortedMap<String, Integer> map = createUnfiltered();
assertTrue(Maps.filterKeys((Map<String, Integer>) map, NOT_LENGTH_3)
instanceof SortedMap);
}

public void testFilterValuesIdentifiesSortedMap() {
SortedMap<String, Integer> map = createUnfiltered();
assertTrue(Maps.filterValues((Map<String, Integer>) map, EVEN)
instanceof SortedMap);
}

public void testFilterEntriesIdentifiesSortedMap() {
SortedMap<String, Integer> map = createUnfiltered();
assertTrue(Maps.filterEntries((Map<String, Integer>) map, CORRECT_LENGTH)
instanceof SortedMap);
}

public void testFirstAndLastKeyFilteredMap() {
SortedMap<String, Integer> unfiltered = createUnfiltered();
unfiltered.put("apple", 2);
Expand Down Expand Up @@ -1607,24 +1578,6 @@ public static class FilteredBiMapTest extends FilteredMapTest {
BiMap<String, Integer> createUnfiltered() {
return HashBiMap.create();
}

public void testFilterKeysIdentifiesBiMap() {
BiMap<String, Integer> map = createUnfiltered();
assertTrue(Maps.filterKeys((Map<String, Integer>) map, NOT_LENGTH_3)
instanceof BiMap);
}

public void testFilterValuesIdentifiesBiMap() {
BiMap<String, Integer> map = createUnfiltered();
assertTrue(Maps.filterValues((Map<String, Integer>) map, EVEN)
instanceof BiMap);
}

public void testFilterEntriesIdentifiesBiMap() {
BiMap<String, Integer> map = createUnfiltered();
assertTrue(Maps.filterEntries((Map<String, Integer>) map, CORRECT_LENGTH)
instanceof BiMap);
}
}

public void testTransformValues() {
Expand All @@ -1634,30 +1587,6 @@ public void testTransformValues() {
assertEquals(ImmutableMap.of("a", 2.0, "b", 3.0), transformed);
}

public void testTransformValuesSecretlySorted() {
Map<String, Integer> map =
sortedNotNavigable(ImmutableSortedMap.of("a", 4, "b", 9));
Map<String, Double> transformed = transformValues(map, SQRT_FUNCTION);

assertEquals(ImmutableMap.of("a", 2.0, "b", 3.0), transformed);
assertTrue(transformed instanceof SortedMap);
}

@GwtIncompatible // NavigableMap
public void testTransformValuesSecretlyNavigable() {
Map<String, Integer> map = ImmutableSortedMap.of("a", 4, "b", 9);
Map<String, Double> transformed;

transformed = transformValues(map, SQRT_FUNCTION);
assertEquals(ImmutableMap.of("a", 2.0, "b", 3.0), transformed);
assertTrue(transformed instanceof NavigableMap);

transformed =
transformValues((SortedMap<String, Integer>) map, SQRT_FUNCTION);
assertEquals(ImmutableMap.of("a", 2.0, "b", 3.0), transformed);
assertTrue(transformed instanceof NavigableMap);
}

public void testTransformEntries() {
Map<String, String> map = ImmutableMap.of("a", "4", "b", "9");
EntryTransformer<String, String, String> concat =
Expand All @@ -1672,42 +1601,6 @@ public String transformEntry(String key, String value) {
assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
}

public void testTransformEntriesSecretlySorted() {
Map<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;
}
};
Map<String, String> transformed = transformEntries(map, concat);

assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
assertTrue(transformed instanceof SortedMap);
}

@GwtIncompatible // NavigableMap
public void testTransformEntriesSecretlyNavigable() {
Map<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;
}
};
Map<String, String> transformed;

transformed = transformEntries(map, concat);
assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
assertTrue(transformed instanceof NavigableMap);

transformed = transformEntries((SortedMap<String, String>) map, concat);
assertEquals(ImmutableMap.of("a", "a4", "b", "b9"), transformed);
assertTrue(transformed instanceof NavigableMap);
}

@SuppressWarnings("unused")
public void testTransformEntriesGenerics() {
Map<Object, Object> map1 = ImmutableMap.<Object, Object>of(1, 2);
Expand Down

0 comments on commit 2d97fd8

Please sign in to comment.