de.enough.polish.util
Class Arrays

java.lang.Object
  extended by de.enough.polish.util.Arrays
All Implemented Interfaces:
Comparator

public final class Arrays
extends java.lang.Object
implements Comparator

Arrays is used for sorting array elements. When no comparator is specified, the default toString() comparator is used. That comparator just compares the string values of the elements using the toString() method.

Copyright (c) Enough Software 2006 - 2008

Author:
Tim Muders, Robert Virkus

Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
           
static boolean equals(java.lang.Object array1, java.lang.Object array2)
          Compares two given array on equality.
static void iQuick(int[] array, int elements)
           
static void quicksort(java.lang.Object[] obj)
           
static void quicksort(java.lang.Object[] obj, int elements, Comparator comparator)
           
static void shellSort(java.lang.Object[] array)
          Sorts the given array using the shell sorting algorithm and the default toString() comparator.
static void shellSort(java.lang.Object[] array, Comparator comparator)
          Sorts the given array using the shell sorting algorithm.
static void sort(java.lang.Object[] obj)
          Sorts the objects using the standard shell sort implementation and the toString() comparator.
static void sort(java.lang.Object[] obj, Comparator comparator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Specified by:
compare in interface Comparator

sort

public static void sort(java.lang.Object[] obj)
Sorts the objects using the standard shell sort implementation and the toString() comparator.

Parameters:
obj - the array of objects that is sorted

shellSort

public static void shellSort(java.lang.Object[] array)
Sorts the given array using the shell sorting algorithm and the default toString() comparator. The shell sort is not as fast as the default quicksort, but it uses less resources and is well suited to sort less than 5,000 entries.

Parameters:
array - the array elements that should be sorted

shellSort

public static void shellSort(java.lang.Object[] array,
                             Comparator comparator)
Sorts the given array using the shell sorting algorithm. The shell sort is not as fast as the default quicksort, but it uses less resources and is well suited to sort less than 5,000 entries.

Parameters:
array - the array elements that should be sorted
comparator - the comparator used for comparing the entries

quicksort

public static void quicksort(java.lang.Object[] obj)

iQuick

public static void iQuick(int[] array,
                          int elements)

quicksort

public static void quicksort(java.lang.Object[] obj,
                             int elements,
                             Comparator comparator)

sort

public static void sort(java.lang.Object[] obj,
                        Comparator comparator)

equals

public static boolean equals(java.lang.Object array1,
                             java.lang.Object array2)
Compares two given array on equality. You can test primitive arrays (like int[] or float[]) and Object based arrays. Ob Object arrays the equals() method is used for comparison.

Parameters:
array1 - the first array
array2 - the second array
Returns:
true when both arrays contain equal elements
Throws:
java.lang.ClassCastException - when the arrays do have different types and the first one has a primitive type