Skip to content

Instantly share code, notes, and snippets.

@mediavrog
Forked from mmarcon/CollectionUtils.java
Last active August 26, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mediavrog/bd15c50191b54a395303 to your computer and use it in GitHub Desktop.
Save mediavrog/bd15c50191b54a395303 to your computer and use it in GitHub Desktop.
package es.cloudey.pagespeed.util;
import java.util.HashMap;
import java.util.Map;
import android.os.Bundle;
import android.os.Parcelable;
public class CollectionUtils {
public static Bundle toBundle(Map<String, ? extends Parcelable> input) {
Bundle output = new Bundle();
for(String key : input.keySet()) {
output.putParcelable(key, input.get(key));
}
return output;
}
public static <T extends Parcelable> Map<String, T> fromBundle(Bundle input, Class<T> c) {
Map<String, T> output = new HashMap<String, T>();
for(String key : input.keySet()) {
output.put(key, c.cast(input.getParcelable(key)));
}
return output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment