BundleCollectionUtil


@UnstableApi
public final class BundleCollectionUtil


Utilities for converting collections to and from Bundle instances.

Summary

Public methods

static HashMap<StringString>
static ImmutableMap<StringString>
static void

Sets the application class loader to the given Bundle if no class loader is present.

static ImmutableList<T>
<T extends Object> fromBundleList(
    Function<Bundle, T> fromBundleFunc,
    List<Bundle> bundleList
)

Unbundles a list of Bundle instances to a list of objects.

static SparseArray<T>
<T extends Object> fromBundleSparseArray(
    Function<Bundle, T> fromBundleFunc,
    SparseArray<Bundle> bundleSparseArray
)

Unbundles a SparseArray of Bundle instances to a SparseArray of objects.

static Bundle
getBundleWithDefault(Bundle bundle, String field, Bundle defaultValue)
static ArrayList<Integer>
getIntegerArrayListWithDefault(
    Bundle bundle,
    String field,
    ArrayList<Integer> defaultValue
)
static Bundle
static ArrayList<Bundle>
<T extends Object> toBundleArrayList(
    Collection<T> items,
    Function<T, Bundle> toBundleFunc
)

Bundles a collection of objects to an ArrayList of Bundle instances so that the returned list can be put to Bundle using putParcelableArrayList conveniently.

static ImmutableList<Bundle>
<T extends Object> toBundleList(List<T> list, Function<T, Bundle> toBundleFunc)

Bundles a list of objects to a list of Bundle instances.

static SparseArray<Bundle>
<T extends Object> toBundleSparseArray(
    SparseArray<T> items,
    Function<T, Bundle> toBundleFunc
)

Bundles a SparseArray of objects to a SparseArray of Bundle instances so that the returned SparseArray can be put to Bundle using putSparseParcelableArray conveniently.

Public methods

bundleToStringHashMap

public static HashMap<StringStringbundleToStringHashMap(Bundle bundle)

bundleToStringImmutableMap

public static ImmutableMap<StringStringbundleToStringImmutableMap(Bundle bundle)

ensureClassLoader

public static void ensureClassLoader(@Nullable Bundle bundle)

Sets the application class loader to the given Bundle if no class loader is present.

This assumes that all classes unparceled from bundle are sharing the class loader of BundleCollectionUtil.

fromBundleList

public static ImmutableList<T> <T extends Object> fromBundleList(
    Function<Bundle, T> fromBundleFunc,
    List<Bundle> bundleList
)

Unbundles a list of Bundle instances to a list of objects.

Parameters
Function<Bundle, T> fromBundleFunc

Function that specified how to unbundle each item.

List<Bundle> bundleList

List of Bundle instances to be unbundled.

Returns
ImmutableList<T>

The ImmutableList of unbundled items.

fromBundleSparseArray

public static SparseArray<T> <T extends Object> fromBundleSparseArray(
    Function<Bundle, T> fromBundleFunc,
    SparseArray<Bundle> bundleSparseArray
)

Unbundles a SparseArray of Bundle instances to a SparseArray of objects.

Parameters
Function<Bundle, T> fromBundleFunc

Function that specified how to unbundle each item.

SparseArray<Bundle> bundleSparseArray

SparseArray of Bundle instances to be unbundled.

Returns
SparseArray<T>

The SparseArray of unbundled items.

getBundleWithDefault

public static Bundle getBundleWithDefault(Bundle bundle, String field, Bundle defaultValue)

getIntegerArrayListWithDefault

public static ArrayList<IntegergetIntegerArrayListWithDefault(
    Bundle bundle,
    String field,
    ArrayList<Integer> defaultValue
)

stringMapToBundle

public static Bundle stringMapToBundle(Map<StringString> map)

toBundleArrayList

public static ArrayList<Bundle> <T extends Object> toBundleArrayList(
    Collection<T> items,
    Function<T, Bundle> toBundleFunc
)

Bundles a collection of objects to an ArrayList of Bundle instances so that the returned list can be put to Bundle using putParcelableArrayList conveniently.

Parameters
Collection<T> items

Collection of items to be bundled.

Function<T, Bundle> toBundleFunc

Function that specifies how to bundle each item.

Returns
ArrayList<Bundle>

The ArrayList of bundled items.

toBundleList

public static ImmutableList<Bundle> <T extends Object> toBundleList(List<T> list, Function<T, Bundle> toBundleFunc)

Bundles a list of objects to a list of Bundle instances.

Parameters
List<T> list

List of items to be bundled.

Function<T, Bundle> toBundleFunc

Function that specifies how to bundle each item.

Returns
ImmutableList<Bundle>

The ImmutableList of bundled items.

toBundleSparseArray

public static SparseArray<Bundle> <T extends Object> toBundleSparseArray(
    SparseArray<T> items,
    Function<T, Bundle> toBundleFunc
)

Bundles a SparseArray of objects to a SparseArray of Bundle instances so that the returned SparseArray can be put to Bundle using putSparseParcelableArray conveniently.

Parameters
SparseArray<T> items

Collection of items to be bundled.

Function<T, Bundle> toBundleFunc

Function that specifies how to bundle each item.

Returns
SparseArray<Bundle>

The SparseArray of bundled items.