Class ArrayFactory


  • public final class ArrayFactory
    extends java.lang.Object
    The factory class ArrayFactory provides factory methods for create new Array objects
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayFactory()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T[] newArray​(java.lang.Class<T> cls, int length)
      Factory method for create new array from the given class type and the given length
      static <T> T[] newArray​(T... elements)
      Factory method for create new array from the given optional elements.
      static boolean[] newBooleanArray​(boolean... elements)
      Factory method for create new array of primitive boolean values from the given optional elements.
      static byte[] newByteArray​(byte... elements)
      Factory method for create new array of primitive byte values from the given optional elements.
      static char[] newCharArray​(char... elements)
      Factory method for create new array of primitive character values from the given optional elements.
      static double[] newDoubleArray​(double... elements)
      Factory method for create new array of primitive double values from the given optional elements.
      static <T> T[] newEmptyArray​(@NonNull T[] array)
      Factory method for create new empty array with the length of the given array
      static <T> T[] newEmptyArray​(@NonNull T[] array, int length)
      Factory method for create new empty array with the length of the given array.
      static float[] newFloatArray​(float... elements)
      Factory method for create new array of primitive float values from the given optional elements.
      static int[] newIntArray​(int... elements)
      Factory method for create new array of primitive integer values from the given optional elements.
      static long[] newLongArray​(long... elements)
      Factory method for create new array of primitive long values from the given optional elements.
      static java.lang.Integer[] newRangeArray​(int start, int end)
      Creates a new Integer array with the given range that is defined through start and end.
      static short[] newShortArray​(short... elements)
      Factory method for create new array of primitive short values from the given optional elements.
      static <T> T[] newSubArray​(@NonNull T[] source, int startIndex, int endIndex)
      Creates a new partial array from the given source array starting from the given start index that is inclusive and the end index that is exclusive
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArrayFactory

        public ArrayFactory()
    • Method Detail

      • newArray

        public static <T> T[] newArray​(java.lang.Class<T> cls,
                                       int length)
        Factory method for create new array from the given class type and the given length
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        cls - the class type
        length - the capacity
        Returns:
        the new array of the given class type and the given length
      • newArray

        @SafeVarargs
        public static <T> T[] newArray​(T... elements)
        Factory method for create new array from the given optional elements.
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        elements - the optional elements that will be in the returned array.
        Returns:
        the new array
      • newEmptyArray

        public static <T> T[] newEmptyArray​(@NonNull
                                            @NonNull T[] array)
        Factory method for create new empty array with the length of the given array
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        array - the array that is used as a template
        Returns:
        the new empty array
      • newEmptyArray

        public static <T> T[] newEmptyArray​(@NonNull
                                            @NonNull T[] array,
                                            int length)
        Factory method for create new empty array with the length of the given array.
        Type Parameters:
        T - the generic type of the elements
        Parameters:
        array - the array that is used as a template
        length - the length of the new empty array
        Returns:
        the new empty array
      • newRangeArray

        public static java.lang.Integer[] newRangeArray​(int start,
                                                        int end)
        Creates a new Integer array with the given range that is defined through start and end. For instance if the start is 5 and the end is 9 the resulted array will be [5,6,7,8,9]
        Parameters:
        start - The number to start
        end - The number to end minus one
        Returns:
        the generated Integer array
      • newBooleanArray

        @SafeVarargs
        public static boolean[] newBooleanArray​(boolean... elements)
        Factory method for create new array of primitive boolean values from the given optional elements.
        Parameters:
        elements - the optional primitive boolean values that will be in the returned array of primitive boolean values array.
        Returns:
        the new array of primitive boolean values
      • newByteArray

        @SafeVarargs
        public static byte[] newByteArray​(byte... elements)
        Factory method for create new array of primitive byte values from the given optional elements.
        Parameters:
        elements - the optional primitive byte values that will be in the returned array of primitive byte values array.
        Returns:
        the new array of primitive byte values
      • newCharArray

        @SafeVarargs
        public static char[] newCharArray​(char... elements)
        Factory method for create new array of primitive character values from the given optional elements.
        Parameters:
        elements - the optional primitive character values that will be in the returned array of primitive character values array.
        Returns:
        the new array of primitive character values
      • newIntArray

        @SafeVarargs
        public static int[] newIntArray​(int... elements)
        Factory method for create new array of primitive integer values from the given optional elements.
        Parameters:
        elements - the optional primitive integer values that will be in the returned array of primitive integer values array.
        Returns:
        the new array of primitive integer values
      • newLongArray

        @SafeVarargs
        public static long[] newLongArray​(long... elements)
        Factory method for create new array of primitive long values from the given optional elements.
        Parameters:
        elements - the optional primitive long values that will be in the returned array of primitive long values array.
        Returns:
        the new array of primitive long values
      • newFloatArray

        @SafeVarargs
        public static float[] newFloatArray​(float... elements)
        Factory method for create new array of primitive float values from the given optional elements.
        Parameters:
        elements - the optional primitive float values that will be in the returned array of primitive float values array.
        Returns:
        the new array of primitive float values
      • newDoubleArray

        @SafeVarargs
        public static double[] newDoubleArray​(double... elements)
        Factory method for create new array of primitive double values from the given optional elements.
        Parameters:
        elements - the optional primitive double values that will be in the returned array of primitive double values array.
        Returns:
        the new array of primitive double values
      • newShortArray

        @SafeVarargs
        public static short[] newShortArray​(short... elements)
        Factory method for create new array of primitive short values from the given optional elements.
        Parameters:
        elements - the optional primitive short values that will be in the returned array of primitive short values array.
        Returns:
        the new array of primitive short values
      • newSubArray

        public static <T> T[] newSubArray​(@NonNull
                                          @NonNull T[] source,
                                          int startIndex,
                                          int endIndex)
        Creates a new partial array from the given source array starting from the given start index that is inclusive and the end index that is exclusive
        Type Parameters:
        T - the generic type
        Parameters:
        source - the source array
        startIndex - the start index that is inclusive
        endIndex - the end index that is exclusive
        Returns:
        the new partial array