Class ArrayUtils

java.lang.Object
edu.gvsu.kurmasz.warszawa.util.ArrayUtils

public class ArrayUtils
extends java.lang.Object
A set of useful methods for dealing with arrays (different from those in Java.util.Arrays).
Author:
Zachary Kurmas
  • Constructor Summary

    Constructors 
    Constructor Description
    ArrayUtils()  
  • Method Summary

    Modifier and Type Method Description
    static void permute​(int[] array)
    Randomly permute the values in array.
    static void permute​(int[] array, java.util.Random rnd)
    Randomly permute the values in array.
    static <T> void permute​(T[] array)
    Randomly permute the values in array.
    static <T> void permute​(T[] array, java.util.Random rnd)
    Randomly permute the values in array.
    static int[] shrinkToFit​(int[] array, int size)
    Generate and fill a new array with no extra room.
    static long[] shrinkToFit​(long[] array, int size)
    Generate and fill a new array with no extra room.
    static <T> T[] shrinkToFit​(T[] array, int size)
    Generate and fill a new array with no extra room.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • shrinkToFit

      public static long[] shrinkToFit​(long[] array, int size)
      Generate and fill a new array with no extra room. Note: For consistency (i.e., having the method always return a new object), a new array is generated, even if array.length == size. If array.length == 0 then array is returned (because array is immutable).
      Parameters:
      array - the array to "shrink".
      size - the number of elements in the array to keep.
      Returns:
      a new array containing the first size elements of array. (See note above.)
      Throws:
      java.lang.IllegalArgumentException - if size > array.length.
    • shrinkToFit

      public static int[] shrinkToFit​(int[] array, int size)
      Generate and fill a new array with no extra room. Note: For consistency (i.e., having the method always return a new object), a new array is generated, even if array.length == size. If array.length == 0 then array is returned (because array is immutable).
      Parameters:
      array - the array to "shrink".
      size - the number of elements in the array to keep.
      Returns:
      a new array containing the first size elements of array. (See note above.)
      Throws:
      java.lang.IllegalArgumentException - if size > array.length.
    • shrinkToFit

      public static <T> T[] shrinkToFit​(T[] array, int size)
      Generate and fill a new array with no extra room. Note: For consistency (i.e., having the method always return a new object), a new array is generated, even if array.length == size. If array.length == 0 then array is returned (because array is immutable).
      Parameters:
      array - the array to "shrink".
      size - the number of elements in the array to keep.
      Returns:
      a new array containing the first size elements of array. (See note above.)
      Throws:
      java.lang.IllegalArgumentException - if size > array.length.
    • permute

      public static <T> void permute​(T[] array, java.util.Random rnd)
      Randomly permute the values in array.
      Parameters:
      array - the array to permute
      rnd - the java.util.Random object used to determine where values are randomly moved.
    • permute

      public static <T> void permute​(T[] array)
      Randomly permute the values in array.
      Parameters:
      array - the array to permute
    • permute

      public static void permute​(int[] array, java.util.Random rnd)
      Randomly permute the values in array.
      Parameters:
      array - the array to permute
      rnd - the java.util.Random object used to determine where values are randomly moved.
    • permute

      public static void permute​(int[] array)
      Randomly permute the values in array.
      Parameters:
      array - the array to permute