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_ARRAY
static byte[]
EMPTY_BYTE_ARRAY
static char[]
EMPTY_CHAR_ARRAY
static CharSequence
EMPTY_CHAR_SEQUENCE
static Class[]
EMPTY_CLASS_ARRAY
static Collection[]
EMPTY_COLLECTION_ARRAY
static int[]
EMPTY_INT_ARRAY
static long[]
EMPTY_LONG_ARRAY
static Object[]
EMPTY_OBJECT_ARRAY
static short[]
EMPTY_SHORT_ARRAY
static 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)
Appendselement
to thesrc
array.static <T> T[]
append(T[] src, T element, ArrayFactory<T> factory)
static <T> T[]
append(T[] src, T element, Class<T> componentType)
static boolean
contains(Object o, Object... objects)
static <E> E[]
ensureExactSize(int count, E[] sample)
static <T> boolean
equals(T[] a1, T[] a2, Comparator<? super T> comparator)
static int
find(int[] src, int obj)
static <T> int
find(T[] src, T obj)
static int
indexOf(int[] ints, int value)
static int
indexOf(Object[] objects, Object object)
static <T> int
lastIndexOf(T[] src, T obj)
static int
lexicographicCompare(String[] obj1, String[] obj2)
static <T> int
lexicographicCompare(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 ofarray
andcollection
to 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 indexidx
from 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 void
reverse(char[] array)
static int[]
reverseArray(int[] array)
static <T> T[]
reverseArray(T[] array)
static <T> void
rotateLeft(T[] array, int i1, int i2)
static <T> void
rotateRight(T[] array, int i1, int i2)
static boolean
startsWith(byte[] array, byte[] subArray)
static boolean
startsWith(byte[] array, int start, byte[] subArray)
static <E> boolean
startsWith(E[] array, E[] subArray)
static void
swap(boolean[] array, int i1, int i2)
static void
swap(char[] array, int i1, int i2)
static void
swap(int[] array, int i1, int i2)
static <T> void
swap(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 ofarray
andcollection
to 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)
Appendselement
to thesrc
array. As you can imagine the appended element will be the last one in the returned result.- Parameters:
src
- array to which theelement
should be appended.element
- object to be appended to the end ofsrc
array.
-
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 indexidx
from 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
obj
in thesrc
array. Returns-1
if passed object isn't found. This method usesequals
of arrays elements to compareobj
with 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)
-
-