Package com.intellij.util
Class ArrayUtil
- java.lang.Object
-
- com.intellij.util.ArrayUtil
-
public class ArrayUtil extends Object
Author: msk
-
-
Field Summary
Fields Modifier and Type Field Description static boolean[]EMPTY_BOOLEAN_ARRAYstatic byte[]EMPTY_BYTE_ARRAYstatic char[]EMPTY_CHAR_ARRAYstatic CharSequenceEMPTY_CHAR_SEQUENCEstatic Class[]EMPTY_CLASS_ARRAYstatic Collection[]EMPTY_COLLECTION_ARRAYstatic int[]EMPTY_INT_ARRAYstatic long[]EMPTY_LONG_ARRAYstatic Object[]EMPTY_OBJECT_ARRAYstatic short[]EMPTY_SHORT_ARRAYstatic String[]EMPTY_STRING_ARRAY
-
Constructor Summary
Constructors Constructor Description ArrayUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[]append(int[] array, int value)static <T> T[]append(T[] src, T element)Appendselementto thesrcarray.static <T> T[]append(T[] src, T element, ArrayFactory<T> factory)static <T> T[]append(T[] src, T element, Class<T> componentType)static booleancontains(Object o, Object... objects)static <E> E[]ensureExactSize(int count, E[] sample)static <T> booleanequals(T[] a1, T[] a2, Comparator<? super T> comparator)static intfind(int[] src, int obj)static <T> intfind(T[] src, T obj)static intindexOf(int[] ints, int value)static intindexOf(Object[] objects, Object object)static <T> intlastIndexOf(T[] src, T obj)static intlexicographicCompare(String[] obj1, String[] obj2)static <T> intlexicographicCompare(T[] obj1, T[] obj2)static <T> T[]mergeArrayAndCollection(T[] array, Collection<T> collection, ArrayFactory<T> factory)Allocates new array of sizearray.length + collection.size()and copies elements ofarrayandcollectionto it.static int[]mergeArrays(int[] a1, int[] a2)static <T> T[]mergeArrays(T[] a1, T[] a2, Class<T> aClass)static int[]newIntArray(int count)static String[]newStringArray(int count)static byte[]realloc(byte[] array, int newSize)static char[]realloc(char[] array, int newSize)static int[]realloc(int[] array, int newSize)static int[]remove(int[] src, int idx)static <T> T[]remove(T[] src, int idx)Removes element with indexidxfrom arraysrc.static <T> T[]remove(T[] src, int idx, ArrayFactory<T> factory)static <T> T[]remove(T[] src, T element)static <T> T[]remove(T[] src, T element, ArrayFactory<T> factory)static voidreverse(char[] array)static int[]reverseArray(int[] array)static <T> T[]reverseArray(T[] array)static <T> voidrotateLeft(T[] array, int i1, int i2)static <T> voidrotateRight(T[] array, int i1, int i2)static booleanstartsWith(byte[] array, byte[] subArray)static booleanstartsWith(byte[] array, int start, byte[] subArray)static <E> booleanstartsWith(E[] array, E[] subArray)static voidswap(boolean[] array, int i1, int i2)static voidswap(char[] array, int i1, int i2)static voidswap(int[] array, int i1, int i2)static <T> voidswap(T[] array, int i1, int i2)static <T> T[]toObjectArray(Class<T> aClass, Object... source)static Object[]toObjectArray(Collection<?> collection)static <T> T[]toObjectArray(Collection<T> collection, Class<T> aClass)static String[]toStringArray(Collection<String> collection)
-
-
-
Field Detail
-
EMPTY_SHORT_ARRAY
public static final short[] EMPTY_SHORT_ARRAY
-
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAY
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
-
EMPTY_INT_ARRAY
public static final int[] EMPTY_INT_ARRAY
-
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAY
-
EMPTY_OBJECT_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
-
EMPTY_CLASS_ARRAY
public static final Class[] EMPTY_CLASS_ARRAY
-
EMPTY_LONG_ARRAY
public static final long[] EMPTY_LONG_ARRAY
-
EMPTY_COLLECTION_ARRAY
public static final Collection[] EMPTY_COLLECTION_ARRAY
-
EMPTY_CHAR_SEQUENCE
public static final CharSequence EMPTY_CHAR_SEQUENCE
-
-
Method Detail
-
realloc
@NotNull public static byte[] realloc(@NotNull byte[] array, int newSize)
-
realloc
@NotNull public static int[] realloc(@NotNull int[] array, int newSize)
-
append
@NotNull public static int[] append(@NotNull int[] array, int value)
-
realloc
@NotNull public static char[] realloc(@NotNull char[] array, int newSize)
-
toObjectArray
@NotNull public static <T> T[] toObjectArray(@NotNull Collection<T> collection, @NotNull Class<T> aClass)
-
toObjectArray
@NotNull public static <T> T[] toObjectArray(@NotNull Class<T> aClass, Object... source)
-
toObjectArray
@NotNull public static Object[] toObjectArray(@NotNull Collection<?> collection)
-
toStringArray
@NotNull public static String[] toStringArray(@NotNull Collection<String> collection)
-
mergeArrays
@NotNull public static <T> T[] mergeArrays(@NotNull T[] a1, @NotNull T[] a2, @NotNull Class<T> aClass)
-
mergeArrays
@NotNull public static int[] mergeArrays(@NotNull int[] a1, @NotNull int[] a2)
-
mergeArrayAndCollection
@NotNull public static <T> T[] mergeArrayAndCollection(@NotNull T[] array, @NotNull Collection<T> collection, @NotNull ArrayFactory<T> factory)Allocates new array of sizearray.length + collection.size()and copies elements ofarrayandcollectionto it.- Parameters:
array- source arraycollection- source collectionfactory- array factory used to create destination array of typeT- Returns:
- destination array
-
append
@NotNull public static <T> T[] append(@NotNull T[] src, T element)Appendselementto thesrcarray. As you can imagine the appended element will be the last one in the returned result.- Parameters:
src- array to which theelementshould be appended.element- object to be appended to the end ofsrcarray.
-
append
public static <T> T[] append(@NotNull T[] src, T element, ArrayFactory<T> factory)
-
append
@NotNull public static <T> T[] append(@NotNull T[] src, T element, @NotNull Class<T> componentType)
-
remove
@NotNull public static <T> T[] remove(@NotNull T[] src, int idx)Removes element with indexidxfrom arraysrc.- Parameters:
src- array.idx- index of element to be removed.- Returns:
- modified array.
-
remove
@NotNull public static <T> T[] remove(@NotNull T[] src, int idx, ArrayFactory<T> factory)
-
remove
@NotNull public static <T> T[] remove(@NotNull T[] src, T element)
-
remove
@NotNull public static <T> T[] remove(@NotNull T[] src, T element, ArrayFactory<T> factory)
-
remove
@NotNull public static int[] remove(@NotNull int[] src, int idx)
-
find
public static <T> int find(@NotNull T[] src, T obj)- Parameters:
src- source array.obj- object to be found.- Returns:
- index of
objin thesrcarray. Returns-1if passed object isn't found. This method usesequalsof arrays elements to compareobjwith these elements.
-
lastIndexOf
public static <T> int lastIndexOf(@NotNull T[] src, T obj)
-
find
public static int find(@NotNull int[] src, int obj)
-
startsWith
public static boolean startsWith(byte[] array, byte[] subArray)
-
startsWith
public static <E> boolean startsWith(E[] array, E[] subArray)
-
startsWith
public static boolean startsWith(@NotNull byte[] array, int start, @NotNull byte[] subArray)
-
equals
public static <T> boolean equals(T[] a1, T[] a2, Comparator<? super T> comparator)
-
reverseArray
@NotNull public static <T> T[] reverseArray(@NotNull T[] array)
-
reverseArray
@NotNull public static int[] reverseArray(@NotNull int[] array)
-
reverse
public static void reverse(@NotNull char[] array)
-
lexicographicCompare
public static int lexicographicCompare(@NotNull String[] obj1, @NotNull String[] obj2)
-
lexicographicCompare
public static <T> int lexicographicCompare(@NotNull T[] obj1, @NotNull T[] obj2)
-
swap
public static <T> void swap(@NotNull T[] array, int i1, int i2)
-
swap
public static void swap(@NotNull int[] array, int i1, int i2)
-
swap
public static void swap(@NotNull boolean[] array, int i1, int i2)
-
swap
public static void swap(@NotNull char[] array, int i1, int i2)
-
rotateLeft
public static <T> void rotateLeft(@NotNull T[] array, int i1, int i2)
-
rotateRight
public static <T> void rotateRight(@NotNull T[] array, int i1, int i2)
-
indexOf
public static int indexOf(@NotNull int[] ints, int value)
-
newIntArray
public static int[] newIntArray(int count)
-
newStringArray
public static String[] newStringArray(int count)
-
ensureExactSize
@NotNull public static <E> E[] ensureExactSize(int count, @NotNull E[] sample)
-
-