Merge "Adding typed Parcel readMap and readHashMap APIs."
This commit is contained in:
@@ -31467,6 +31467,7 @@ package android.os {
|
|||||||
method public float readFloat();
|
method public float readFloat();
|
||||||
method public void readFloatArray(@NonNull float[]);
|
method public void readFloatArray(@NonNull float[]);
|
||||||
method @Nullable public java.util.HashMap readHashMap(@Nullable ClassLoader);
|
method @Nullable public java.util.HashMap readHashMap(@Nullable ClassLoader);
|
||||||
|
method @Nullable public <K, V> java.util.HashMap<K,V> readHashMap(@Nullable ClassLoader, @NonNull Class<? extends K>, @NonNull Class<? extends V>);
|
||||||
method public int readInt();
|
method public int readInt();
|
||||||
method public void readIntArray(@NonNull int[]);
|
method public void readIntArray(@NonNull int[]);
|
||||||
method public <T extends android.os.IInterface> void readInterfaceArray(@NonNull T[], @NonNull java.util.function.Function<android.os.IBinder,T>);
|
method public <T extends android.os.IInterface> void readInterfaceArray(@NonNull T[], @NonNull java.util.function.Function<android.os.IBinder,T>);
|
||||||
@@ -31476,6 +31477,7 @@ package android.os {
|
|||||||
method public long readLong();
|
method public long readLong();
|
||||||
method public void readLongArray(@NonNull long[]);
|
method public void readLongArray(@NonNull long[]);
|
||||||
method public void readMap(@NonNull java.util.Map, @Nullable ClassLoader);
|
method public void readMap(@NonNull java.util.Map, @Nullable ClassLoader);
|
||||||
|
method public <K, V> void readMap(@NonNull java.util.Map<? super K,? super V>, @Nullable ClassLoader, @NonNull Class<K>, @NonNull Class<V>);
|
||||||
method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader);
|
method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader);
|
||||||
method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader, @NonNull Class<T>);
|
method @Nullable public <T extends android.os.Parcelable> T readParcelable(@Nullable ClassLoader, @NonNull Class<T>);
|
||||||
method @Nullable public android.os.Parcelable[] readParcelableArray(@Nullable ClassLoader);
|
method @Nullable public android.os.Parcelable[] readParcelableArray(@Nullable ClassLoader);
|
||||||
|
|||||||
@@ -2992,8 +2992,24 @@ public final class Parcel {
|
|||||||
* from the parcel at the current dataPosition().
|
* from the parcel at the current dataPosition().
|
||||||
*/
|
*/
|
||||||
public final void readMap(@NonNull Map outVal, @Nullable ClassLoader loader) {
|
public final void readMap(@NonNull Map outVal, @Nullable ClassLoader loader) {
|
||||||
int N = readInt();
|
int n = readInt();
|
||||||
readMapInternal(outVal, N, loader);
|
readMapInternal(outVal, n, loader, /* clazzKey */ null, /* clazzValue */ null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as {@link #readMap(Map, ClassLoader)} but accepts {@code clazzKey} and
|
||||||
|
* {@code clazzValue} parameter as the types required for each key and value pair.
|
||||||
|
*
|
||||||
|
* @throws BadParcelableException If the item to be deserialized is not an instance of that
|
||||||
|
* class or any of its children class
|
||||||
|
*/
|
||||||
|
public <K, V> void readMap(@NonNull Map<? super K, ? super V> outVal,
|
||||||
|
@Nullable ClassLoader loader, @NonNull Class<K> clazzKey,
|
||||||
|
@NonNull Class<V> clazzValue) {
|
||||||
|
Objects.requireNonNull(clazzKey);
|
||||||
|
Objects.requireNonNull(clazzValue);
|
||||||
|
int n = readInt();
|
||||||
|
readMapInternal(outVal, n, loader, clazzKey, clazzValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3031,15 +3047,37 @@ public final class Parcel {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public final HashMap readHashMap(@Nullable ClassLoader loader)
|
public final HashMap readHashMap(@Nullable ClassLoader loader)
|
||||||
{
|
{
|
||||||
int N = readInt();
|
int n = readInt();
|
||||||
if (N < 0) {
|
if (n < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
HashMap m = new HashMap(N);
|
HashMap m = new HashMap(n);
|
||||||
readMapInternal(m, N, loader);
|
readMapInternal(m, n, loader, /* clazzKey */ null, /* clazzValue */ null);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as {@link #readHashMap(ClassLoader)} but accepts {@code clazzKey} and
|
||||||
|
* {@code clazzValue} parameter as the types required for each key and value pair.
|
||||||
|
*
|
||||||
|
* @throws BadParcelableException if the item to be deserialized is not an instance of that
|
||||||
|
* class or any of its children class
|
||||||
|
*/
|
||||||
|
@SuppressLint({"ConcreteCollection", "NullableCollection"})
|
||||||
|
@Nullable
|
||||||
|
public <K, V> HashMap<K, V> readHashMap(@Nullable ClassLoader loader,
|
||||||
|
@NonNull Class<? extends K> clazzKey, @NonNull Class<? extends V> clazzValue) {
|
||||||
|
Objects.requireNonNull(clazzKey);
|
||||||
|
Objects.requireNonNull(clazzValue);
|
||||||
|
int n = readInt();
|
||||||
|
if (n < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
HashMap<K, V> map = new HashMap<>(n);
|
||||||
|
readMapInternal(map, n, loader, clazzKey, clazzValue);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read and return a new Bundle object from the parcel at the current
|
* Read and return a new Bundle object from the parcel at the current
|
||||||
* dataPosition(). Returns null if the previously written Bundle object was
|
* dataPosition(). Returns null if the previously written Bundle object was
|
||||||
@@ -4472,13 +4510,23 @@ public final class Parcel {
|
|||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ void readMapInternal(@NonNull Map outVal, int N,
|
/**
|
||||||
|
* To be replaced by {@link #readMapInternal(Map, int, ClassLoader, Class, Class)}, but keep
|
||||||
|
* the old API for compatibility usages.
|
||||||
|
*/
|
||||||
|
/* package */ void readMapInternal(@NonNull Map outVal, int n,
|
||||||
@Nullable ClassLoader loader) {
|
@Nullable ClassLoader loader) {
|
||||||
while (N > 0) {
|
readMapInternal(outVal, n, loader, /* clazzKey */null, /* clazzValue */null);
|
||||||
Object key = readValue(loader);
|
}
|
||||||
Object value = readValue(loader);
|
|
||||||
|
/* package */ <K, V> void readMapInternal(@NonNull Map<? super K, ? super V> outVal, int n,
|
||||||
|
@Nullable ClassLoader loader, @Nullable Class<K> clazzKey,
|
||||||
|
@Nullable Class<V> clazzValue) {
|
||||||
|
while (n > 0) {
|
||||||
|
K key = readValue(loader, clazzKey);
|
||||||
|
V value = readValue(loader, clazzValue);
|
||||||
outVal.put(key, value);
|
outVal.put(key, value);
|
||||||
N--;
|
n--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user