Class ManArrayExt


  • public class ManArrayExt
    extends Object
    Adds convenience methods to Java's array type. Uses @Self to enforce type-safety with both the array type and the array component type.
    • Constructor Detail

      • ManArrayExt

        public ManArrayExt()
    • Method Detail

      • toList

        public static List<Object> toList​(Object array)
        Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray(). The returned list is serializable and implements RandomAccess.
        Returns:
        a list view of the specified array
      • isEmpty

        public static boolean isEmpty​(Object array)
      • isNullOrEmpty

        public static boolean isNullOrEmpty​(Object array)
      • copy

        public static Object copy​(Object array,
                                  int newLength)
        Copies this array's elements into a new array of the specified newLength. If newLength is < 0, the new array's size matches this array, otherwise the new array is truncated or padded with null as newLength differs from this array's length.
        Parameters:
        newLength - The length of the new array. If < 0, the resulting array's length matches this array, otherwise the resulting array is truncated or padded with null accordingly.
        Returns:
        A newly allocated array with elements corresponding with this array.
      • copyTo

        public static Object copyTo​(Object array,
                                    Object to)
        Copies the elements of this array to a specified array, truncating or padding with nulls as needed.
      • copyRange

        public static Object copyRange​(Object array,
                                       int from,
                                       int to)
        Copies a range of elements from this array to a newly allocated array. Note, if to < 0, the range contains the remainder of this array's elements.
        Parameters:
        from - The start point of the range, inclusive.
        to - The endpoint of the range, exclusive. A negative value may be used as a convenience to use this array's endpoint.
        Returns:
        A newly allocated array containing the specified range of elements from this array.
      • copyRangeTo

        public static Object copyRangeTo​(Object array,
                                         int from,
                                         int to,
                                         Object target,
                                         int targetIndex)
        Copies a range of elements from this array to the target array. Note, if to < 0, the range contains the remainder of this array's elements.
        Parameters:
        from - The starting point of the range, inclusive.
        to - The endpoint of the range, exclusive. A negative value may be used as a convenience to use this array's endpoint.
        Returns:
        The target array containing the specified range of elements from this array.
      • stream

        public static Stream<Object> stream​(Object array)
        Returns a sequential Stream with this array as its source. Note, this array is assumed to be unmodified during use
        Returns:
        A Stream for the array
      • binarySearch

        public static int binarySearch​(Object array,
                                       Object key)
      • binarySearch

        public static int binarySearch​(Object array,
                                       int from,
                                       int to,
                                       Object key)
      • toString

        public static String toString​(Object array)
      • hashCode

        public static int hashCode​(Object array)
      • equals

        public static boolean equals​(Object array,
                                     Object that)