package androidx.media3.common.util; import android.os.Bundle; import android.util.SparseArray; import androidx.media3.common.Bundleable; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; /* loaded from: classes2.dex */ public final class BundleableUtil { public static ImmutableList toBundleList(List list) { return toBundleList(list, new Function() { // from class: androidx.media3.common.util.BundleableUtil$$ExternalSyntheticLambda0 @Override // com.google.common.base.Function public final Object apply(Object obj) { return ((Bundleable) obj).toBundle(); } }); } public static ImmutableList toBundleList(List list, Function function) { ImmutableList.Builder builder = ImmutableList.builder(); for (int i = 0; i < list.size(); i++) { builder.add((ImmutableList.Builder) function.apply(list.get(i))); } return builder.build(); } public static ImmutableList fromBundleList(Bundleable.Creator creator, List list) { ImmutableList.Builder builder = ImmutableList.builder(); for (int i = 0; i < list.size(); i++) { builder.add((ImmutableList.Builder) creator.fromBundle((Bundle) Assertions.checkNotNull(list.get(i)))); } return builder.build(); } public static ArrayList toBundleArrayList(Collection collection) { ArrayList arrayList = new ArrayList<>(collection.size()); Iterator it = collection.iterator(); while (it.hasNext()) { arrayList.add(it.next().toBundle()); } return arrayList; } public static SparseArray fromBundleSparseArray(Bundleable.Creator creator, SparseArray sparseArray) { SparseArray sparseArray2 = new SparseArray<>(sparseArray.size()); for (int i = 0; i < sparseArray.size(); i++) { sparseArray2.put(sparseArray.keyAt(i), creator.fromBundle(sparseArray.valueAt(i))); } return sparseArray2; } public static SparseArray toBundleSparseArray(SparseArray sparseArray) { SparseArray sparseArray2 = new SparseArray<>(sparseArray.size()); for (int i = 0; i < sparseArray.size(); i++) { sparseArray2.put(sparseArray.keyAt(i), sparseArray.valueAt(i).toBundle()); } return sparseArray2; } public static Bundle stringMapToBundle(Map map) { Bundle bundle = new Bundle(); for (Map.Entry entry : map.entrySet()) { bundle.putString(entry.getKey(), entry.getValue()); } return bundle; } public static HashMap bundleToStringHashMap(Bundle bundle) { HashMap hashMap = new HashMap<>(); if (bundle == Bundle.EMPTY) { return hashMap; } for (String str : bundle.keySet()) { String string = bundle.getString(str); if (string != null) { hashMap.put(str, string); } } return hashMap; } public static ImmutableMap bundleToStringImmutableMap(Bundle bundle) { if (bundle == Bundle.EMPTY) { return ImmutableMap.of(); } return ImmutableMap.copyOf((Map) bundleToStringHashMap(bundle)); } public static Bundle getBundleWithDefault(Bundle bundle, String str, Bundle bundle2) { Bundle bundle3 = bundle.getBundle(str); return bundle3 != null ? bundle3 : bundle2; } public static ArrayList getIntegerArrayListWithDefault(Bundle bundle, String str, ArrayList arrayList) { ArrayList integerArrayList = bundle.getIntegerArrayList(str); return integerArrayList != null ? integerArrayList : arrayList; } public static void ensureClassLoader(Bundle bundle) { if (bundle != null) { bundle.setClassLoader((ClassLoader) Util.castNonNull(BundleableUtil.class.getClassLoader())); } } private BundleableUtil() { } }