Created
March 29, 2017 14:24
-
-
Save Lamorak/0da071962ae0eb1c6ca25915608957c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.os.Bundle; | |
| import android.os.IBinder; | |
| import android.os.Parcelable; | |
| import android.support.annotation.NonNull; | |
| import android.util.Size; | |
| import android.util.SizeF; | |
| import android.util.SparseArray; | |
| import java.io.Serializable; | |
| import java.util.ArrayList; | |
| public class BundleBuilder { | |
| private final Bundle bundle; | |
| public static BundleBuilder create() { | |
| return new BundleBuilder(); | |
| } | |
| private BundleBuilder() { | |
| bundle = new Bundle(); | |
| } | |
| public static Bundle single(@NonNull final String key, final String value) { | |
| return BundleBuilder.create() | |
| .with(key, value) | |
| .build(); | |
| } | |
| public static Bundle single(@NonNull final String key, final int value) { | |
| return BundleBuilder.create() | |
| .with(key, value) | |
| .build(); | |
| } | |
| public static Bundle single(@NonNull final String key, final boolean value) { | |
| return BundleBuilder.create() | |
| .with(key, value) | |
| .build(); | |
| } | |
| public BundleBuilder with(@NonNull final String key, final String value) { | |
| bundle.putString(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final byte value) { | |
| bundle.putByte(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final char value) { | |
| bundle.putChar(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final short value) { | |
| bundle.putShort(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final float value) { | |
| bundle.putFloat(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final CharSequence value) { | |
| bundle.putCharSequence(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final Parcelable value) { | |
| bundle.putParcelable(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final Size value) { | |
| bundle.putSize(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final SizeF value) { | |
| bundle.putSizeF(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final Parcelable[] value) { | |
| bundle.putParcelableArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder withParcelables(@NonNull final String key, final ArrayList<? extends Parcelable> value) { | |
| bundle.putParcelableArrayList(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final SparseArray<? extends Parcelable> value) { | |
| bundle.putSparseParcelableArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder withIntegers(@NonNull final String key, final ArrayList<Integer> value) { | |
| bundle.putIntegerArrayList(key, value); | |
| return this; | |
| } | |
| public BundleBuilder withStrings(@NonNull final String key, final ArrayList<String> value) { | |
| bundle.putStringArrayList(key, value); | |
| return this; | |
| } | |
| public BundleBuilder withCharSequences(@NonNull final String key, final ArrayList<CharSequence> value) { | |
| bundle.putCharSequenceArrayList(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final Serializable value) { | |
| bundle.putSerializable(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final byte[] value) { | |
| bundle.putByteArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final short[] value) { | |
| bundle.putShortArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final char[] value) { | |
| bundle.putCharArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final float[] value) { | |
| bundle.putFloatArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final CharSequence[] value) { | |
| bundle.putCharSequenceArray(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final Bundle value) { | |
| bundle.putBundle(key, value); | |
| return this; | |
| } | |
| public BundleBuilder with(@NonNull final String key, final IBinder value) { | |
| bundle.putBinder(key, value); | |
| return this; | |
| } | |
| public Bundle build() { | |
| return bundle; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment