java.lang.Object
org.tquadrat.foundation.util.ArrayUtils

@UtilityClass @ClassVersion(sourceVersion="$Id: ArrayUtils.java 1060 2023-09-24 19:21:40Z tquadrat $") public final class ArrayUtils extends Object
This class provides some utility functions that extends Arrays to some extent. All methods are static, no objects of this class are allowed.
Author:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: ArrayUtils.java 1060 2023-09-24 19:21:40Z tquadrat $
Since:
0.0.5
UML Diagram
UML Diagram for "org.tquadrat.foundation.util.ArrayUtils"

UML Diagram for "org.tquadrat.foundation.util.ArrayUtils"

UML Diagram for "org.tquadrat.foundation.util.ArrayUtils"
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The illegal index message.
    static final String
    "The message indicates that the given value is not an array."
    static final String
    The message indicates that the given value set is empty.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Prevent the creation of any object of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> boolean
    isComparableIn(Comparable<? super T> o, T... list)
    This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter.
    static <T> boolean
    isEqualIn(T o, T... list)
    This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter.
    static boolean
    isIn(byte v, byte... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static boolean
    isIn(char v, char... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static boolean
    isIn(double v, double... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static boolean
    isIn(float v, float... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static boolean
    isIn(int v, int... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static boolean
    isIn(long v, long... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static boolean
    isIn(short v, short... list)
    This method checks if the given value is at least once in the list that is provided as the second parameter.
    static <T> boolean
    isIn(T o, T... list)
    This method checks if the given object is in the list of objects that is provided as the second parameter.
    static char
    max(char... list)
    Determines the greatest value in the given array.
    static double
    max(double... list)
    Determines the greatest value in the given array.
    static int
    max(int... list)
    Determines the greatest value in the given array.
    static long
    max(long... list)
    Determines the greatest value in the given array.
    static <T> T
    max(Comparator<? super T> comparator, T... list)
    Determines the greatest value in the given array, based on the given Comparator.
    static <T extends Comparable<T>>
    T
    max(T... list)
    Determines the greatest value in the given array.
    static char
    min(char... list)
    Determines the smallest value in the given array.
    static double
    min(double... list)
    Determines the smallest value in the given array.
    static int
    min(int... list)
    Determines the smallest value in the given array.
    static long
    min(long... list)
    Determines the smallest value in the given array.
    static <T> T
    min(Comparator<? super T> comparator, T... list)
    Determines the smallest value in the given array, based on the given Comparator.
    static <T extends Comparable<T>>
    T
    min(T... list)
    Determines the smallest value in the given array.
    static <T> void
    revert(T... a)
    Modifies the given array to contain the elements in reverted order.
    static <T> T[]
    revertCopy(T... a)
    Returns a copy of the given array with the elements in reverted order.
    static <T> T[]
    subArray(T[] source, int start)
    Returns a part of the given array as a copy, beginning with the given start position to the end of the array.
    static <T> T[]
    subArray(T[] source, int start, int len)
    Returns a part of the given array as a copy.

    The semantics of this method are slightly different from that in Arrays.
    static Object[]
    Translates the given array to an array of element type Object.
    static String
    toString(Object[] array, CharSequence separator)
    Renders the given array to a single string where the elements are separated by the given character sequence.

    This method allows to control the output a bit better than Arrays.toString(Object[]), Objects.toString(Object), or Objects.toString(Object).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ArrayUtils

      private ArrayUtils()
      Prevent the creation of any object of this class.
  • Method Details

    • toObjectArray

      @API(status=STABLE, since="0.0.5") public static Object[] toObjectArray(Object array)
      Translates the given array to an array of element type Object. Primitive types will be automatically converted into the respective Wrapper types.

      The array elements will not be copied.
      Parameters:
      array - The array to translate.
      Returns:
      The translated array.
    • isComparableIn

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> boolean isComparableIn(Comparable<? super T> o, T... list)
      This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter. The test is made using compareTo(). For a test on object identity, using ==, use isIn().
      Type Parameters:
      T - The class for the objects.
      Parameters:
      o - The object to look for.
      list - The list of object to look into.
      Returns:
      true if the object is in the list, false otherwise.
      Throws:
      NullPointerException - At least one entry of list is null.
    • isEqualIn

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> boolean isEqualIn(T o, T... list)
      This method checks if the array of objects that is provided as the second parameter contains an object that is equal to that one provided as the first parameter. The test is made using equals(). For a test on object identity, using ==, use isIn().
      Type Parameters:
      T - The class for the objects.
      Parameters:
      o - The object to look for.
      list - The list of object to look into.
      Returns:
      true if the object is in the list, false otherwise.
    • isIn

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> boolean isIn(T o, T... list)
      This method checks if the given object is in the list of objects that is provided as the second parameter. The test is made on object identity, using ==. For a test with equals(), use isEqualIn()
      Type Parameters:
      T - The class for the objects.
      Parameters:
      o - The object to look for; may be null.
      list - The list of object to look into.
      Returns:
      true if the object is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(byte v, byte... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(char v, char... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(double v, double... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter. The test is made on identity, using ==; this means, due to the nature of double, that values may not be found, although they appear to be equal.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(float v, float... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter. The test is made on identity, using ==; this means, due to the nature of float, that values may not be found, although they appear to be equal.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(int v, int... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(long v, long... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • isIn

      @API(status=STABLE, since="0.0.5") public static boolean isIn(short v, short... list)
      This method checks if the given value is at least once in the list that is provided as the second parameter.
      Parameters:
      v - The value to look for.
      list - The list of values to look into.
      Returns:
      true if the value is in the list, false otherwise.
    • max

      @SafeVarargs @API(status=STABLE, since="0.1.0") public static <T> T max(Comparator<? super T> comparator, T... list)
      Determines the greatest value in the given array, based on the given Comparator.
      Type Parameters:
      T - The class for the objects.
      Parameters:
      comparator - The comparator to use.
      list - The values.
      Returns:
      The greatest value in the list.
    • max

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T extends Comparable<T>> T max(T... list)
      Determines the greatest value in the given array.
      Type Parameters:
      T - The class for the objects.
      Parameters:
      list - The values.
      Returns:
      The greatest value in the list.
    • max

      @API(status=STABLE, since="0.0.5") public static char max(char... list)
      Determines the greatest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The greatest value in the list.
    • max

      @API(status=STABLE, since="0.0.5") public static double max(double... list)
      Determines the greatest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The greatest value in the list.
    • max

      @API(status=STABLE, since="0.0.5") public static int max(int... list)
      Determines the greatest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The greatest value in the list.
    • max

      @API(status=STABLE, since="0.0.5") public static long max(long... list)
      Determines the greatest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The greatest value in the list.
    • min

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> T min(Comparator<? super T> comparator, T... list)
      Determines the smallest value in the given array, based on the given Comparator.
      Type Parameters:
      T - The class for the objects.
      Parameters:
      comparator - The comparator.
      list - The values.
      Returns:
      The smallest value in the list.
    • min

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T extends Comparable<T>> T min(T... list)
      Determines the smallest value in the given array.
      Type Parameters:
      T - The class for the objects.
      Parameters:
      list - The values.
      Returns:
      The smallest value in the list.
    • min

      @API(status=STABLE, since="0.0.5") public static char min(char... list)
      Determines the smallest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The smallest value in the list.
    • min

      @API(status=STABLE, since="0.0.5") public static double min(double... list)
      Determines the smallest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The smallest value in the list.
    • min

      @API(status=STABLE, since="0.0.5") public static int min(int... list)
      Determines the smallest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The smallest value in the list.
    • min

      @API(status=STABLE, since="0.0.5") public static long min(long... list)
      Determines the smallest value in the given array.
      Parameters:
      list - The values.
      Returns:
      The smallest value in the list.
    • revert

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> void revert(T... a)
      Modifies the given array to contain the elements in reverted order.
      Type Parameters:
      T - The type of the array elements.
      Parameters:
      a - The array to revert.
    • revertCopy

      @SafeVarargs @API(status=STABLE, since="0.0.5") public static <T> T[] revertCopy(T... a)
      Returns a copy of the given array with the elements in reverted order.
      Type Parameters:
      T - The type of the array elements.
      Parameters:
      a - The array to revert.
      Returns:
      The copy in reverted order.
    • subArray

      @API(status=STABLE, since="0.0.5") public static <T> T[] subArray(T[] source, int start, int len)
      Returns a part of the given array as a copy.

      The semantics of this method are slightly different from that in Arrays.
      Type Parameters:
      T - The type of the array elements.
      Parameters:
      source - The source array.
      start - The start index.
      len - The number of elements for the partial array.
      Returns:
      The new array.
      See Also:
    • subArray

      @API(status=STABLE, since="0.0.5") public static <T> T[] subArray(T[] source, int start)
      Returns a part of the given array as a copy, beginning with the given start position to the end of the array.
      Type Parameters:
      T - The type of the array elements.
      Parameters:
      source - The source array.
      start - The start index.
      Returns:
      The new array.
    • toString

      @API(status=STABLE, since="0.0.5") public static String toString(Object[] array, CharSequence separator)
      Renders the given array to a single string where the elements are separated by the given character sequence.

      This method allows to control the output a bit better than Arrays.toString(Object[]), Objects.toString(Object), or Objects.toString(Object). Especially it does not frame the output with those square brackets ...
      Parameters:
      array - The input array.
      separator - The separator character sequence; if null, the empty string is used.
      Returns:
      The concatenated string.