Class Utils

java.lang.Object
net.thevpc.common.util.Utils

public class Utils extends Object
Author:
taha.bensalah@gmail.com
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • compare

      public static int compare(Object a, Object b)
    • compare

      public static int compare(Object a, Object b, Comparator c)
    • joinArrays

      public static Object joinArrays(Object... arrays)
    • joinArraysAsType

      public static Object joinArraysAsType(Class componentType, Object... arrays)
    • copyOfArray

      public static Object copyOfArray(Object array)
    • removeArrayTail

      public static Object removeArrayTail(Object array, int offset, int removeCount)
    • removeArray

      public static Object removeArray(Object array, int offset, int removeCount)
    • ifType

      public static <T, V> V ifType(Object object, Class<T> type, Function<T,V> r)
    • ncastDo

      public static <T> void ncastDo(Class<T> type, Object object, DoWith<T> r)
    • ncast

      public static <T> T ncast(Class<T> type, Object object)
    • isEmpty

      public static boolean isEmpty(Object object)
    • nonNullValue

      public static Object nonNullValue(Object... objects)
    • nonEmptyValue

      public static Object nonEmptyValue(Object... objects)
    • fibonacci

      public static int fibonacci(int number)
    • rand

      public static int rand(int min, int max)
    • rand

      public static <T> T rand(List<T> values)
    • rand

      public static <T> T rand(T[] values)
    • rand

      public static <T> T rand(Class<T> enumType)
    • inUseMemory

      public static long inUseMemory()
    • maxFreeMemory

      public static long maxFreeMemory()
    • compare

      public static int compare(byte x, byte y)
    • compare

      public static int compare(int x, int y)
    • compare

      public static int compare(long x, long y)
    • compare

      public static int compare(double d1, double d2)
    • compare

      public static int compare(float f1, float f2)
    • hashCode

      public static int hashCode(Object o)
    • copyOf

      public static <T> T[] copyOf(T[] original, int newLength)
    • copyOf

      public static <T, U> T[] copyOf(U[] original, int newLength, Class<? extends T[]> newType)
    • copyOf

      public static short[] copyOf(short[] original, int newLength)
    • copyOf

      public static int[] copyOf(int[] original, int newLength)
      Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain 0. Such indices will exist if and only if the specified length is greater than that of the original array.
      Parameters:
      original - the array to be copied
      newLength - the length of the copy to be returned
      Returns:
      a copy of the original array, truncated or padded with zeros to obtain the specified length
      Throws:
      NegativeArraySizeException - if newLength is negative
      NullPointerException - if original is null
      Since:
      1.6
    • copyOf

      public static long[] copyOf(long[] original, int newLength)
      Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain 0L. Such indices will exist if and only if the specified length is greater than that of the original array.
      Parameters:
      original - the array to be copied
      newLength - the length of the copy to be returned
      Returns:
      a copy of the original array, truncated or padded with zeros to obtain the specified length
      Throws:
      NegativeArraySizeException - if newLength is negative
      NullPointerException - if original is null
      Since:
      1.6
    • copyOf

      public static char[] copyOf(char[] original, int newLength)
      Copies the specified array, truncating or padding with null characters (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain '\\u000'. Such indices will exist if and only if the specified length is greater than that of the original array.
      Parameters:
      original - the array to be copied
      newLength - the length of the copy to be returned
      Returns:
      a copy of the original array, truncated or padded with null characters to obtain the specified length
      Throws:
      NegativeArraySizeException - if newLength is negative
      NullPointerException - if original is null
      Since:
      1.6
    • copyOf

      public static float[] copyOf(float[] original, int newLength)
      Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain 0f. Such indices will exist if and only if the specified length is greater than that of the original array.
      Parameters:
      original - the array to be copied
      newLength - the length of the copy to be returned
      Returns:
      a copy of the original array, truncated or padded with zeros to obtain the specified length
      Throws:
      NegativeArraySizeException - if newLength is negative
      NullPointerException - if original is null
      Since:
      1.6
    • copyOf

      public static double[] copyOf(double[] original, int newLength)
      Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain 0d. Such indices will exist if and only if the specified length is greater than that of the original array.
      Parameters:
      original - the array to be copied
      newLength - the length of the copy to be returned
      Returns:
      a copy of the original array, truncated or padded with zeros to obtain the specified length
      Throws:
      NegativeArraySizeException - if newLength is negative
      NullPointerException - if original is null
      Since:
      1.6
    • copyOf

      public static boolean[] copyOf(boolean[] original, int newLength)
      Copies the specified array, truncating or padding with false (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical values. For any indices that are valid in the copy but not the original, the copy will contain false. Such indices will exist if and only if the specified length is greater than that of the original array.
      Parameters:
      original - the array to be copied
      newLength - the length of the copy to be returned
      Returns:
      a copy of the original array, truncated or padded with false elements to obtain the specified length
      Throws:
      NegativeArraySizeException - if newLength is negative
      NullPointerException - if original is null
      Since:
      1.6
    • sort

      public static <T, V> List<T> sort(List<T> list, Function<T,V> converter, Comparator<V> c)
    • sort

      public static <T, V> T[] sort(T[] arr, Function<T,V> converter, Comparator<V> c)