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
Object> fromBundleList(
    Function<Bundle, T> fromBundleFunc,
    List<Bundle> bundleList
)

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

static SparseArray
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>
Object> toBundleArrayList(
    Collection items,
    FunctionBundle> 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>
Object> toBundleList(List list, FunctionBundle> toBundleFunc)

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

static SparseArray<Bundle>
Object> toBundleSparseArray(
    SparseArray items,
    FunctionBundle> 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 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

The ImmutableList of unbundled items.

fromBundleSparseArray

public static SparseArray 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

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<BundleObject> toBundleArrayList(
    Collection items,
    FunctionBundle> 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 items

Collection of items to be bundled.

FunctionBundle> toBundleFunc

Function that specifies how to bundle each item.

Returns
ArrayList<Bundle>

The ArrayList of bundled items.

toBundleList

public static ImmutableList<BundleObject> toBundleList(List list, FunctionBundle> toBundleFunc)

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

Parameters
List list

List of items to be bundled.

FunctionBundle> toBundleFunc

Function that specifies how to bundle each item.

Returns
ImmutableList<Bundle>

The ImmutableList of bundled items.

toBundleSparseArray

public static SparseArray<BundleObject> toBundleSparseArray(
    SparseArray items,
    FunctionBundle> 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 items

Collection of items to be bundled.

FunctionBundle> toBundleFunc

Function that specifies how to bundle each item.

Returns
SparseArray<Bundle>

The SparseArray of bundled items.