Package com.android.internal.util
Class ArrayUtils
- java.lang.Object
-
- com.android.internal.util.ArrayUtils
-
public class ArrayUtils extends java.lang.ObjectArrayUtils contains some methods that you can call to find out the most efficient increments by which to grow arrays.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> android.util.ArraySet<T>add(android.util.ArraySet<T> cur, T val)static <T> java.util.ArrayList<T>add(java.util.ArrayList<T> cur, T val)static <T> T[]appendElement(java.lang.Class<T> kind, T[] array, T element)Adds value to given array if not already present, providing set-like behavior.static <T> T[]appendElement(java.lang.Class<T> kind, T[] array, T element, boolean allowDuplicates)Adds value to given array.static int[]appendInt(int[] cur, int val)Adds value to given array if not already present, providing set-like behavior.static int[]appendInt(int[] cur, int val, boolean allowDuplicates)Adds value to given array.static long[]appendLong(long[] cur, long val)Adds value to given array if not already present, providing set-like behavior.static long[]appendLong(long[] cur, long val, boolean allowDuplicates)Adds value to given array if not already present, providing set-like behavior.static long[]cloneOrNull(long[] array)static <T> android.util.ArraySet<T>cloneOrNull(android.util.ArraySet<T> array)static booleancontains(char[] array, char value)static booleancontains(int[] array, int value)static booleancontains(long[] array, long value)static <T> booleancontains(java.util.Collection<T> cur, T val)static <T> booleancontains(T[] array, T value)Checks that value is present as at least one of the elements of the array.static <T> booleancontainsAll(char[] array, char[] check)Test if allcheckitems are contained inarray.static <T> booleancontainsAll(T[] array, T[] check)Test if allcheckitems are contained inarray.static <T> booleancontainsAny(T[] array, T[] check)Test if anycheckitems are contained inarray.static int[]convertToIntArray(java.util.List<java.lang.Integer> list)static long[]convertToLongArray(int[] intArray)static int[]defeatNullable(int[] val)static java.lang.String[]defeatNullable(java.lang.String[] val)static <T> T[]emptyArray(java.lang.Class<T> kind)Returns an empty array of the specified type.static booleanequals(byte[] array1, byte[] array2, int length)Checks if the beginnings of two byte arrays are equal.static <T> intindexOf(T[] array, T value)Return first index ofvalueinarray, or-1if not found.static booleanisEmpty(boolean[] array)Checks if given array is null or has zero elements.static booleanisEmpty(byte[] array)Checks if given array is null or has zero elements.static booleanisEmpty(int[] array)Checks if given array is null or has zero elements.static booleanisEmpty(long[] array)Checks if given array is null or has zero elements.static booleanisEmpty(java.util.Collection<?> array)Checks if given array is null or has zero elements.static booleanisEmpty(java.util.Map<?,?> map)Checks if given map is null or has zero elements.static <T> booleanisEmpty(T[] array)Checks if given array is null or has zero elements.static <T> T[]newUnpaddedArray(java.lang.Class<T> clazz, int minLen)static boolean[]newUnpaddedBooleanArray(int minLen)static byte[]newUnpaddedByteArray(int minLen)static char[]newUnpaddedCharArray(int minLen)static float[]newUnpaddedFloatArray(int minLen)static int[]newUnpaddedIntArray(int minLen)static long[]newUnpaddedLongArray(int minLen)static java.lang.Object[]newUnpaddedObjectArray(int minLen)static <T> booleanreferenceEquals(java.util.ArrayList<T> a, java.util.ArrayList<T> b)Returns true if the two ArrayLists are equal with respect to the objects they contain.static <T> android.util.ArraySet<T>remove(android.util.ArraySet<T> cur, T val)static <T> java.util.ArrayList<T>remove(java.util.ArrayList<T> cur, T val)static <T> T[]removeElement(java.lang.Class<T> kind, T[] array, T element)Removes value from given array if present, providing set-like behavior.static int[]removeInt(int[] cur, int val)Removes value from given array if present, providing set-like behavior.static long[]removeLong(long[] cur, long val)Removes value from given array if present, providing set-like behavior.static java.lang.String[]removeString(java.lang.String[] cur, java.lang.String val)Removes value from given array if present, providing set-like behavior.static intsize(java.lang.Object[] array)Length of the given array or 0 if it's null.static intsize(java.util.Collection<?> collection)Length of the given collection or 0 if it's null.static longtotal(long[] array)static <T> T[]trimToSize(T[] array, int size)static <T> intunstableRemoveIf(java.util.ArrayList<T> collection, java.util.function.Predicate<T> predicate)Removes elements that match the predicate in an efficient way that alters the order of elements in the collection.
-
-
-
Method Detail
-
newUnpaddedByteArray
public static byte[] newUnpaddedByteArray(int minLen)
-
newUnpaddedCharArray
public static char[] newUnpaddedCharArray(int minLen)
-
newUnpaddedIntArray
public static int[] newUnpaddedIntArray(int minLen)
-
newUnpaddedBooleanArray
public static boolean[] newUnpaddedBooleanArray(int minLen)
-
newUnpaddedLongArray
public static long[] newUnpaddedLongArray(int minLen)
-
newUnpaddedFloatArray
public static float[] newUnpaddedFloatArray(int minLen)
-
newUnpaddedObjectArray
public static java.lang.Object[] newUnpaddedObjectArray(int minLen)
-
newUnpaddedArray
public static <T> T[] newUnpaddedArray(java.lang.Class<T> clazz, int minLen)
-
equals
public static boolean equals(byte[] array1, byte[] array2, int length)Checks if the beginnings of two byte arrays are equal.- Parameters:
array1- the first byte arrayarray2- the second byte arraylength- the number of bytes to check- Returns:
- true if they're equal, false otherwise
-
emptyArray
public static <T> T[] emptyArray(java.lang.Class<T> kind)
Returns an empty array of the specified type. The intent is that it will return the same empty array every time to avoid reallocation, although this is not guaranteed.
-
isEmpty
public static boolean isEmpty(java.util.Collection<?> array)
Checks if given array is null or has zero elements.
-
isEmpty
public static boolean isEmpty(java.util.Map<?,?> map)
Checks if given map is null or has zero elements.
-
isEmpty
public static <T> boolean isEmpty(T[] array)
Checks if given array is null or has zero elements.
-
isEmpty
public static boolean isEmpty(int[] array)
Checks if given array is null or has zero elements.
-
isEmpty
public static boolean isEmpty(long[] array)
Checks if given array is null or has zero elements.
-
isEmpty
public static boolean isEmpty(byte[] array)
Checks if given array is null or has zero elements.
-
isEmpty
public static boolean isEmpty(boolean[] array)
Checks if given array is null or has zero elements.
-
size
public static int size(java.lang.Object[] array)
Length of the given array or 0 if it's null.
-
size
public static int size(java.util.Collection<?> collection)
Length of the given collection or 0 if it's null.
-
contains
public static <T> boolean contains(T[] array, T value)Checks that value is present as at least one of the elements of the array.- Parameters:
array- the array to check invalue- the value to check for- Returns:
- true if the value is present in the array
-
indexOf
public static <T> int indexOf(T[] array, T value)Return first index ofvalueinarray, or-1if not found.
-
containsAll
public static <T> boolean containsAll(T[] array, T[] check)Test if allcheckitems are contained inarray.
-
containsAny
public static <T> boolean containsAny(T[] array, T[] check)Test if anycheckitems are contained inarray.
-
contains
public static boolean contains(int[] array, int value)
-
contains
public static boolean contains(long[] array, long value)
-
contains
public static boolean contains(char[] array, char value)
-
containsAll
public static <T> boolean containsAll(char[] array, char[] check)Test if allcheckitems are contained inarray.
-
total
public static long total(long[] array)
-
convertToIntArray
public static int[] convertToIntArray(java.util.List<java.lang.Integer> list)
-
convertToLongArray
public static long[] convertToLongArray(int[] intArray)
-
appendElement
public static <T> T[] appendElement(java.lang.Class<T> kind, T[] array, T element)Adds value to given array if not already present, providing set-like behavior.
-
appendElement
public static <T> T[] appendElement(java.lang.Class<T> kind, T[] array, T element, boolean allowDuplicates)Adds value to given array.
-
removeElement
public static <T> T[] removeElement(java.lang.Class<T> kind, T[] array, T element)Removes value from given array if present, providing set-like behavior.
-
appendInt
public static int[] appendInt(int[] cur, int val, boolean allowDuplicates)Adds value to given array.
-
appendInt
public static int[] appendInt(int[] cur, int val)Adds value to given array if not already present, providing set-like behavior.
-
removeInt
public static int[] removeInt(int[] cur, int val)Removes value from given array if present, providing set-like behavior.
-
removeString
public static java.lang.String[] removeString(java.lang.String[] cur, java.lang.String val)Removes value from given array if present, providing set-like behavior.
-
appendLong
public static long[] appendLong(long[] cur, long val, boolean allowDuplicates)Adds value to given array if not already present, providing set-like behavior.
-
appendLong
public static long[] appendLong(long[] cur, long val)Adds value to given array if not already present, providing set-like behavior.
-
removeLong
public static long[] removeLong(long[] cur, long val)Removes value from given array if present, providing set-like behavior.
-
cloneOrNull
public static long[] cloneOrNull(long[] array)
-
cloneOrNull
public static <T> android.util.ArraySet<T> cloneOrNull(android.util.ArraySet<T> array)
-
add
public static <T> android.util.ArraySet<T> add(android.util.ArraySet<T> cur, T val)
-
remove
public static <T> android.util.ArraySet<T> remove(android.util.ArraySet<T> cur, T val)
-
add
public static <T> java.util.ArrayList<T> add(java.util.ArrayList<T> cur, T val)
-
remove
public static <T> java.util.ArrayList<T> remove(java.util.ArrayList<T> cur, T val)
-
contains
public static <T> boolean contains(java.util.Collection<T> cur, T val)
-
trimToSize
public static <T> T[] trimToSize(T[] array, int size)
-
referenceEquals
public static <T> boolean referenceEquals(java.util.ArrayList<T> a, java.util.ArrayList<T> b)Returns true if the two ArrayLists are equal with respect to the objects they contain. The objects must be in the same order and be reference equal (== not .equals()).
-
unstableRemoveIf
public static <T> int unstableRemoveIf(java.util.ArrayList<T> collection, java.util.function.Predicate<T> predicate)Removes elements that match the predicate in an efficient way that alters the order of elements in the collection. This should only be used if order is not important.- Parameters:
collection- The ArrayList from which to remove elements.predicate- The predicate that each element is tested against.- Returns:
- the number of elements removed.
-
defeatNullable
public static int[] defeatNullable(int[] val)
-
defeatNullable
public static java.lang.String[] defeatNullable(java.lang.String[] val)
-
-