From 9cad0679d3111ef7dce671351dac1fcd28805c52 Mon Sep 17 00:00:00 2001 From: Marcono1234 Date: Tue, 24 Sep 2024 01:52:54 +0200 Subject: [PATCH] Revert some changes for API not available yet in target Android version --- .../com/google/gson/internal/LinkedTreeMap.java | 8 +++++++- .../gson/internal/NonNullElementWrapperList.java | 15 +++------------ .../gson/internal/reflect/ReflectionHelper.java | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java b/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java index 7ba7a84e24..099dd573c0 100644 --- a/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java +++ b/gson/src/main/java/com/google/gson/internal/LinkedTreeMap.java @@ -43,7 +43,13 @@ @SuppressWarnings("serial") // ignore warning about missing serialVersionUID public final class LinkedTreeMap extends AbstractMap implements Serializable { @SuppressWarnings({"unchecked", "rawtypes"}) // to avoid Comparable>> - private static final Comparator NATURAL_ORDER = Comparator.naturalOrder(); + private static final Comparator NATURAL_ORDER = + new Comparator() { + @Override + public int compare(Comparable a, Comparable b) { + return a.compareTo(b); + } + }; private final Comparator comparator; private final boolean allowNullValues; diff --git a/gson/src/main/java/com/google/gson/internal/NonNullElementWrapperList.java b/gson/src/main/java/com/google/gson/internal/NonNullElementWrapperList.java index ae12d4c246..45a9c2905b 100644 --- a/gson/src/main/java/com/google/gson/internal/NonNullElementWrapperList.java +++ b/gson/src/main/java/com/google/gson/internal/NonNullElementWrapperList.java @@ -19,11 +19,9 @@ import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.RandomAccess; -import java.util.Spliterator; /** * {@link List} which wraps another {@code List} but prevents insertion of {@code null} elements. @@ -109,16 +107,6 @@ public int lastIndexOf(Object o) { return delegate.lastIndexOf(o); } - @Override - public Spliterator spliterator() { - return delegate.spliterator(); - } - - @Override - public void sort(Comparator c) { - delegate.sort(c); - } - @Override public Object[] toArray() { return delegate.toArray(); @@ -138,4 +126,7 @@ public boolean equals(Object o) { public int hashCode() { return delegate.hashCode(); } + + // Maybe also delegate List#sort and List#spliterator in the future, but that + // requires Android API level 24 } diff --git a/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java b/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java index ceaf9be742..7a845ce515 100644 --- a/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java +++ b/gson/src/main/java/com/google/gson/internal/reflect/ReflectionHelper.java @@ -128,8 +128,8 @@ public static String constructorToString(Constructor constructor) { return stringBuilder.toString(); } - // Ideally parameter type would be java.lang.reflect.Executable, but that was added in Android API - // level 26 + // Ideally parameter type would be java.lang.reflect.Executable, but that was added + // in Android API level 26 private static void appendExecutableParameters( AccessibleObject executable, StringBuilder stringBuilder) { stringBuilder.append('(');