package org.mtransit.android.commons;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.util.SparseArray;

public class ArrayUtils {

	public static int getSize(SparseArray<?> sparseArray) {
		if (sparseArray == null) {
			return 0;
		}
		return sparseArray.size();
	}

	@SuppressWarnings("unchecked")
	public static <T> int getSize(T... array) {
		if (array == null) {
			return 0;
		}
		return array.length;
	}

	@SuppressWarnings("unchecked")
	public static <T> ArrayList<T> asArrayList(T... array) {
		ArrayList<T> result = new ArrayList<T>();
		if (array != null) {
			Collections.addAll(result, array);
		}
		return result;
	}

	public static String[] addAll(String[] array1, String[] array2) {
		if (array1 == null) {
			return clone(array2);
		} else if (array2 == null) {
			return clone(array1);
		}
		String[] joinedArray = (String[]) Array.newInstance(array1.getClass().getComponentType(), array1.length + array2.length);
		System.arraycopy(array1, 0, joinedArray, 0, array1.length);
		System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
		return joinedArray;
	}

	public static String[] clone(Object[] array) {
		if (array == null) {
			return null;
		}
		return (String[]) array.clone();
	}

	public static List<Integer> asIntegerList(int[] intArray) {
		ArrayList<Integer> result = new ArrayList<Integer>();
		if (intArray != null) {
			for (int integer : intArray) {
				result.add(integer);
			}
		}
		return result;
	}

	public static ArrayList<Integer> asIntegerList(String[] stringArray) {
		ArrayList<Integer> result = new ArrayList<Integer>();
		if (stringArray != null) {
			for (String string : stringArray) {
				result.add(Integer.valueOf(string));
			}
		}
		return result;
	}

	public static ArrayList<Long> asLongList(String[] stringArray) {
		ArrayList<Long> result = new ArrayList<Long>();
		if (stringArray != null) {
			for (String string : stringArray) {
				result.add(Long.valueOf(string));
			}
		}
		return result;
	}

	public static ArrayList<Boolean> asBooleanList(String[] stringArray) {
		ArrayList<Boolean> result = new ArrayList<Boolean>();
		if (stringArray != null) {
			for (String string : stringArray) {
				result.add(Boolean.valueOf(string));
			}
		}
		return result;
	}
}

@@ -146,16 +146,103 @@
 .List;%0A%0A
+import android.support.annotation.NonNull;%0Aimport android.support.annotation.Nullable;%0A
 import a
@@ -321,16 +321,26 @@
 getSize(
+@Nullable 
 SparseAr
@@ -436,24 +436,519 @@
 size();%0A%09%7D%0A%0A
+%0A%09public static boolean containsKey(@Nullable SparseArray%3C?%3E sparseArray, int key) %7B%0A%09%09return sparseArray != null && sparseArray.indexOfKey(key) %3E= 0;%0A%09%7D%0A%0A%09@NonNull%0A%09public static %3CC%3E ArrayList%3CC%3E asArrayList(@Nullable SparseArray%3CC%3E sparseArray) %7B%0A%09%09ArrayList%3CC%3E arrayList = new ArrayList%3CC%3E(sparseArray == null ? 0 : sparseArray.size());%0A%09%09if (sparseArray != null) %7B%0A%09%09%09for (int i = 0; i %3C sparseArray.size(); i++) %7B%0A%09%09%09%09arrayList.add(sparseArray.valueAt(i));%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return arrayList;%0A%09%7D%0A%0A
 %09@SuppressWa

Add SparseArray utility methods.