Merge "Adding typed Parcel readParcelableList API." am: edbe912fd3 am: 42cd062e7b am: 5c971f65aa
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1899430 Change-Id: I4b6ba89f4f7ea913dc0bf7a74c658a39346780f3
This commit is contained in:
@@ -31575,6 +31575,7 @@ package android.os {
|
|||||||
method @Deprecated @Nullable public android.os.Parcelable.Creator<?> readParcelableCreator(@Nullable ClassLoader);
|
method @Deprecated @Nullable public android.os.Parcelable.Creator<?> readParcelableCreator(@Nullable ClassLoader);
|
||||||
method @Nullable public <T> android.os.Parcelable.Creator<T> readParcelableCreator(@Nullable ClassLoader, @NonNull Class<T>);
|
method @Nullable public <T> android.os.Parcelable.Creator<T> readParcelableCreator(@Nullable ClassLoader, @NonNull Class<T>);
|
||||||
method @NonNull public <T extends android.os.Parcelable> java.util.List<T> readParcelableList(@NonNull java.util.List<T>, @Nullable ClassLoader);
|
method @NonNull public <T extends android.os.Parcelable> java.util.List<T> readParcelableList(@NonNull java.util.List<T>, @Nullable ClassLoader);
|
||||||
|
method @NonNull public <T> java.util.List<T> readParcelableList(@NonNull java.util.List<T>, @Nullable ClassLoader, @NonNull Class<T>);
|
||||||
method @Nullable public android.os.PersistableBundle readPersistableBundle();
|
method @Nullable public android.os.PersistableBundle readPersistableBundle();
|
||||||
method @Nullable public android.os.PersistableBundle readPersistableBundle(@Nullable ClassLoader);
|
method @Nullable public android.os.PersistableBundle readPersistableBundle(@Nullable ClassLoader);
|
||||||
method @Deprecated @Nullable public java.io.Serializable readSerializable();
|
method @Deprecated @Nullable public java.io.Serializable readSerializable();
|
||||||
|
|||||||
@@ -3650,22 +3650,47 @@ public final class Parcel {
|
|||||||
@NonNull
|
@NonNull
|
||||||
public final <T extends Parcelable> List<T> readParcelableList(@NonNull List<T> list,
|
public final <T extends Parcelable> List<T> readParcelableList(@NonNull List<T> list,
|
||||||
@Nullable ClassLoader cl) {
|
@Nullable ClassLoader cl) {
|
||||||
final int N = readInt();
|
return readParcelableListInternal(list, cl, /*clazz*/ null);
|
||||||
if (N == -1) {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as {@link #readParcelableList(List, ClassLoader)} but accepts {@code clazz} parameter as
|
||||||
|
* the type required for each item.
|
||||||
|
*
|
||||||
|
* @throws BadParcelableException Throws BadParcelableException if the item to be deserialized
|
||||||
|
* is not an instance of that class or any of its children classes or there was an error
|
||||||
|
* trying to instantiate an element.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public <T> List<T> readParcelableList(@NonNull List<T> list,
|
||||||
|
@Nullable ClassLoader cl, @NonNull Class<T> clazz) {
|
||||||
|
Objects.requireNonNull(list);
|
||||||
|
Objects.requireNonNull(clazz);
|
||||||
|
return readParcelableListInternal(list, cl, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clazz The type of the object expected or {@code null} for performing no checks.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
private <T> List<T> readParcelableListInternal(@NonNull List<T> list,
|
||||||
|
@Nullable ClassLoader cl, @Nullable Class<T> clazz) {
|
||||||
|
final int n = readInt();
|
||||||
|
if (n == -1) {
|
||||||
list.clear();
|
list.clear();
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int M = list.size();
|
final int m = list.size();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < M && i < N; i++) {
|
for (; i < m && i < n; i++) {
|
||||||
list.set(i, (T) readParcelable(cl));
|
list.set(i, (T) readParcelableInternal(cl, clazz));
|
||||||
}
|
}
|
||||||
for (; i<N; i++) {
|
for (; i < n; i++) {
|
||||||
list.add((T) readParcelable(cl));
|
list.add((T) readParcelableInternal(cl, clazz));
|
||||||
}
|
}
|
||||||
for (; i<M; i++) {
|
for (; i < m; i++) {
|
||||||
list.remove(N);
|
list.remove(n);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user