org.jcon.util
Class ArraySorter

java.lang.Object
  extended by org.jcon.util.ArraySorter

public class ArraySorter
extends java.lang.Object

Sorts an array using a Comparer. All static methods. Initially only a few sort types are supported. The example has many. From Nutshell Examples page 36 with minor modifications.

Author:
Jack Harich

Nested Class Summary
static class ArraySorter.ASCIIComparer
          Compares assuming the String is only ASCII.
static interface ArraySorter.Comparer
          The interface implementation should compare the two objects and return an int using these rules: if (a > b) return > 0; if (a == b) return 0; if (a < b) return < 0; For example to sort a String array: ClassName implements ArraySorter.Comparer public int compare(Object a, Object b) { return (the proper int); }
 
Field Summary
static ArraySorter.ASCIIComparer asciiComparer
           
 
Constructor Summary
ArraySorter()
           
 
Method Summary
static void main(java.lang.String[] args)
          Performs a simple unit test by sorting command arguments.
static void sort(java.lang.Object[] a, ArraySorter.Comparer comparer)
          Sorts the array in ascending order using the Comparer.
static void sort(java.lang.Object[] a, java.lang.Object[] b, int from, int to, boolean ascending, ArraySorter.Comparer comparer)
          Sorts both arrays.
static void sortASCII(java.lang.String[] a)
          Sorts an ASCII String array in ascending order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

asciiComparer

public static final ArraySorter.ASCIIComparer asciiComparer
Constructor Detail

ArraySorter

public ArraySorter()
Method Detail

main

public static void main(java.lang.String[] args)
Performs a simple unit test by sorting command arguments.


sortASCII

public static void sortASCII(java.lang.String[] a)
Sorts an ASCII String array in ascending order. Case insensitive, which is usually desired.


sort

public static void sort(java.lang.Object[] a,
                        ArraySorter.Comparer comparer)
Sorts the array in ascending order using the Comparer.


sort

public static void sort(java.lang.Object[] a,
                        java.lang.Object[] b,
                        int from,
                        int to,
                        boolean ascending,
                        ArraySorter.Comparer comparer)
Sorts both arrays. Array @param b is optional. @param from and @param to determine the portion of the arrays sorted, which is usually all. @param ascending is true for an ascending sort, false for decending. The @param comparer is used for object comparisons. Quicksort.