Class ArrayUtil


  • public class ArrayUtil
    extends Object
    Author: msk
    • 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
    • Constructor Detail

      • ArrayUtil

        public ArrayUtil()
    • 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)
      • 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 size array.length + collection.size() and copies elements of array and collection to it.
        Parameters:
        array - source array
        collection - source collection
        factory - array factory used to create destination array of type T
        Returns:
        destination array
      • append

        @NotNull
        public static <T> T[] append​(@NotNull
                                     T[] src,
                                     T element)
        Appends element to the src array. As you can imagine the appended element will be the last one in the returned result.
        Parameters:
        src - array to which the element should be appended.
        element - object to be appended to the end of src 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 index idx from array src.
        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 the src array. Returns -1 if passed object isn't found. This method uses equals of arrays elements to compare obj 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
                                  Object[] objects,
                                  Object object)
      • indexOf

        public static int indexOf​(@NotNull
                                  int[] ints,
                                  int value)
      • contains

        public static boolean contains​(Object o,
                                       Object... objects)
      • 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)