Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 656141716
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jul 25, 2024
1 parent 85c6f88 commit 5827422
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testEquals_list() {
getMap().equals(Helpers.copyToList(getMap().entrySet())));
}

private static <K, V> HashMap<K, V> newHashMap(
private static <K, V> Map<K, V> newHashMap(
Collection<? extends Entry<? extends K, ? extends V>> entries) {
HashMap<K, V> map = new HashMap<>();
for (Entry<? extends K, ? extends V> entry : entries) {
Expand Down
8 changes: 8 additions & 0 deletions android/guava/src/com/google/common/collect/Lists.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private Lists() {}
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList() {
return new ArrayList<>();
}
Expand All @@ -102,6 +103,7 @@ private Lists() {}
*/
@SafeVarargs
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList(E... elements) {
checkNotNull(elements); // for GWT
// Avoid integer overflow when a large array is passed in
Expand All @@ -126,6 +128,7 @@ private Lists() {}
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList(
Iterable<? extends E> elements) {
checkNotNull(elements); // for GWT
Expand All @@ -143,6 +146,7 @@ private Lists() {}
* ImmutableList#copyOf(Iterator)} instead.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList(
Iterator<? extends E> elements) {
ArrayList<E> list = newArrayList();
Expand Down Expand Up @@ -176,6 +180,7 @@ static int computeArrayListCapacity(int arraySize) {
* @throws IllegalArgumentException if {@code initialArraySize} is negative
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayListWithCapacity(
int initialArraySize) {
checkNonnegative(initialArraySize, "initialArraySize"); // for GWT.
Expand All @@ -196,6 +201,7 @@ static int computeArrayListCapacity(int arraySize) {
* @throws IllegalArgumentException if {@code estimatedSize} is negative
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayListWithExpectedSize(
int estimatedSize) {
return new ArrayList<>(computeArrayListCapacity(estimatedSize));
Expand All @@ -220,6 +226,7 @@ static int computeArrayListCapacity(int arraySize) {
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedList<E> newLinkedList() {
return new LinkedList<>();
}
Expand All @@ -243,6 +250,7 @@ static int computeArrayListCapacity(int arraySize) {
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedList<E> newLinkedList(
Iterable<? extends E> elements) {
LinkedList<E> list = newLinkedList();
Expand Down
13 changes: 12 additions & 1 deletion android/guava/src/com/google/common/collect/Maps.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(
*
* @return a new, empty {@code HashMap}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object>
HashMap<K, V> newHashMap() {
return new HashMap<>();
Expand All @@ -256,6 +257,7 @@ HashMap<K, V> newHashMap() {
* @param map the mappings to be placed in the new map
* @return a new {@code HashMap} initialized with the mappings from {@code map}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object> HashMap<K, V> newHashMap(
Map<? extends K, ? extends V> map) {
return new HashMap<>(map);
Expand All @@ -272,6 +274,7 @@ HashMap<K, V> newHashMap() {
* without resizing
* @throws IllegalArgumentException if {@code expectedSize} is negative
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object>
HashMap<K, V> newHashMapWithExpectedSize(int expectedSize) {
return new HashMap<>(capacity(expectedSize));
Expand Down Expand Up @@ -316,6 +319,7 @@ static int capacity(int expectedSize) {
*
* @return a new, empty {@code LinkedHashMap}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object>
LinkedHashMap<K, V> newLinkedHashMap() {
return new LinkedHashMap<>();
Expand All @@ -335,6 +339,7 @@ LinkedHashMap<K, V> newLinkedHashMap() {
* @param map the mappings to be placed in the new map
* @return a new, {@code LinkedHashMap} initialized with the mappings from {@code map}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object>
LinkedHashMap<K, V> newLinkedHashMap(Map<? extends K, ? extends V> map) {
return new LinkedHashMap<>(map);
Expand All @@ -352,6 +357,7 @@ LinkedHashMap<K, V> newLinkedHashMap(Map<? extends K, ? extends V> map) {
* @throws IllegalArgumentException if {@code expectedSize} is negative
* @since 19.0
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object>
LinkedHashMap<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) {
return new LinkedHashMap<>(capacity(expectedSize));
Expand Down Expand Up @@ -379,7 +385,10 @@ public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
*
* @return a new, empty {@code TreeMap}
*/
@SuppressWarnings("rawtypes") // https://github.com/google/guava/issues/989
@SuppressWarnings({
"rawtypes", // https://github.com/google/guava/issues/989
"NonApiType", // acts as a direct substitute for a constructor call
})
public static <K extends Comparable, V extends @Nullable Object> TreeMap<K, V> newTreeMap() {
return new TreeMap<>();
}
Expand All @@ -401,6 +410,7 @@ public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
* @return a new {@code TreeMap} initialized with the mappings from {@code map} and using the
* comparator of {@code map}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <K extends @Nullable Object, V extends @Nullable Object> TreeMap<K, V> newTreeMap(
SortedMap<K, ? extends V> map) {
return new TreeMap<>(map);
Expand All @@ -420,6 +430,7 @@ public static <K, V> ConcurrentMap<K, V> newConcurrentMap() {
* @param comparator the comparator to sort the keys with
* @return a new, empty {@code TreeMap}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <C extends @Nullable Object, K extends C, V extends @Nullable Object>
TreeMap<K, V> newTreeMap(@CheckForNull Comparator<C> comparator) {
// Ideally, the extra type parameter "C" shouldn't be necessary. It is a
Expand Down
19 changes: 17 additions & 2 deletions android/guava/src/com/google/common/collect/Sets.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static <E extends Enum<E>> EnumSet<E> newEnumSet(
* href="https://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation">"diamond"
* syntax</a>.
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> HashSet<E> newHashSet() {
return new HashSet<>();
}
Expand All @@ -197,6 +198,7 @@ public static <E extends Enum<E>> EnumSet<E> newEnumSet(
* asList}{@code (...))}, or for creating an empty set then calling {@link Collections#addAll}.
* This method is not actually very useful and will likely be deprecated in the future.
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> HashSet<E> newHashSet(E... elements) {
HashSet<E> set = newHashSetWithExpectedSize(elements.length);
Collections.addAll(set, elements);
Expand All @@ -222,6 +224,7 @@ public static <E extends Enum<E>> EnumSet<E> newEnumSet(
*
* <p>Overall, this method is not very useful and will likely be deprecated in the future.
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> HashSet<E> newHashSet(Iterable<? extends E> elements) {
return (elements instanceof Collection)
? new HashSet<E>((Collection<? extends E>) elements)
Expand All @@ -240,6 +243,7 @@ public static <E extends Enum<E>> EnumSet<E> newEnumSet(
*
* <p>Overall, this method is not very useful and will likely be deprecated in the future.
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> HashSet<E> newHashSet(Iterator<? extends E> elements) {
HashSet<E> set = newHashSet();
Iterators.addAll(set, elements);
Expand All @@ -258,6 +262,7 @@ public static <E extends Enum<E>> EnumSet<E> newEnumSet(
* without resizing
* @throws IllegalArgumentException if {@code expectedSize} is negative
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> HashSet<E> newHashSetWithExpectedSize(
int expectedSize) {
return new HashSet<>(Maps.capacity(expectedSize));
Expand Down Expand Up @@ -310,6 +315,7 @@ public static <E> Set<E> newConcurrentHashSet(Iterable<? extends E> elements) {
*
* @return a new, empty {@code LinkedHashSet}
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedHashSet<E> newLinkedHashSet() {
return new LinkedHashSet<>();
}
Expand All @@ -330,6 +336,7 @@ public static <E> Set<E> newConcurrentHashSet(Iterable<? extends E> elements) {
* @param elements the elements that the set should contain, in order
* @return a new {@code LinkedHashSet} containing those elements (minus duplicates)
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedHashSet<E> newLinkedHashSet(
Iterable<? extends E> elements) {
if (elements instanceof Collection) {
Expand All @@ -352,6 +359,7 @@ public static <E> Set<E> newConcurrentHashSet(Iterable<? extends E> elements) {
* @throws IllegalArgumentException if {@code expectedSize} is negative
* @since 11.0
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedHashSet<E> newLinkedHashSetWithExpectedSize(
int expectedSize) {
return new LinkedHashSet<>(Maps.capacity(expectedSize));
Expand All @@ -372,7 +380,10 @@ public static <E> Set<E> newConcurrentHashSet(Iterable<? extends E> elements) {
*
* @return a new, empty {@code TreeSet}
*/
@SuppressWarnings("rawtypes") // https://github.com/google/guava/issues/989
@SuppressWarnings({
"rawtypes", // https://github.com/google/guava/issues/989
"NonApiType", // acts as a direct substitute for a constructor call
})
public static <E extends Comparable> TreeSet<E> newTreeSet() {
return new TreeSet<>();
}
Expand All @@ -399,7 +410,10 @@ public static <E extends Comparable> TreeSet<E> newTreeSet() {
* @param elements the elements that the set should contain
* @return a new {@code TreeSet} containing those elements (minus duplicates)
*/
@SuppressWarnings("rawtypes") // https://github.com/google/guava/issues/989
@SuppressWarnings({
"rawtypes", // https://github.com/google/guava/issues/989
"NonApiType", // acts as a direct substitute for a constructor call
})
public static <E extends Comparable> TreeSet<E> newTreeSet(Iterable<? extends E> elements) {
TreeSet<E> set = newTreeSet();
Iterables.addAll(set, elements);
Expand All @@ -423,6 +437,7 @@ public static <E extends Comparable> TreeSet<E> newTreeSet(Iterable<? extends E>
* @return a new, empty {@code TreeSet}
* @throws NullPointerException if {@code comparator} is null
*/
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> TreeSet<E> newTreeSet(
Comparator<? super E> comparator) {
return new TreeSet<>(checkNotNull(comparator));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@
public class TreeBasedTable<R, C, V> extends StandardRowSortedTable<R, C, V> {
private final Comparator<? super C> columnComparator;

private static class Factory<C, V> implements Supplier<TreeMap<C, V>>, Serializable {
private static class Factory<C, V> implements Supplier<Map<C, V>>, Serializable {
final Comparator<? super C> comparator;

Factory(Comparator<? super C> comparator) {
this.comparator = comparator;
}

@Override
public TreeMap<C, V> get() {
public Map<C, V> get() {
return new TreeMap<>(comparator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testEquals_list() {
getMap().equals(Helpers.copyToList(getMap().entrySet())));
}

private static <K, V> HashMap<K, V> newHashMap(
private static <K, V> Map<K, V> newHashMap(
Collection<? extends Entry<? extends K, ? extends V>> entries) {
HashMap<K, V> map = new HashMap<>();
for (Entry<? extends K, ? extends V> entry : entries) {
Expand Down
8 changes: 8 additions & 0 deletions guava/src/com/google/common/collect/Lists.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private Lists() {}
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList() {
return new ArrayList<>();
}
Expand All @@ -103,6 +104,7 @@ private Lists() {}
*/
@SafeVarargs
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList(E... elements) {
checkNotNull(elements); // for GWT
// Avoid integer overflow when a large array is passed in
Expand All @@ -127,6 +129,7 @@ private Lists() {}
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList(
Iterable<? extends E> elements) {
checkNotNull(elements); // for GWT
Expand All @@ -144,6 +147,7 @@ private Lists() {}
* ImmutableList#copyOf(Iterator)} instead.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayList(
Iterator<? extends E> elements) {
ArrayList<E> list = newArrayList();
Expand Down Expand Up @@ -177,6 +181,7 @@ static int computeArrayListCapacity(int arraySize) {
* @throws IllegalArgumentException if {@code initialArraySize} is negative
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayListWithCapacity(
int initialArraySize) {
checkNonnegative(initialArraySize, "initialArraySize"); // for GWT.
Expand All @@ -197,6 +202,7 @@ static int computeArrayListCapacity(int arraySize) {
* @throws IllegalArgumentException if {@code estimatedSize} is negative
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> ArrayList<E> newArrayListWithExpectedSize(
int estimatedSize) {
return new ArrayList<>(computeArrayListCapacity(estimatedSize));
Expand All @@ -221,6 +227,7 @@ static int computeArrayListCapacity(int arraySize) {
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedList<E> newLinkedList() {
return new LinkedList<>();
}
Expand All @@ -244,6 +251,7 @@ static int computeArrayListCapacity(int arraySize) {
* syntax</a>.
*/
@GwtCompatible(serializable = true)
@SuppressWarnings("NonApiType") // acts as a direct substitute for a constructor call
public static <E extends @Nullable Object> LinkedList<E> newLinkedList(
Iterable<? extends E> elements) {
LinkedList<E> list = newLinkedList();
Expand Down
Loading

0 comments on commit 5827422

Please sign in to comment.