wt.sysadm
Class Sorter

java.lang.Object
  extended bywt.sysadm.Sorter

public class Sorter
extends Object

This is a simple instantiable class with four public methods to perform a simple bubble sort on an array of Strings. The four methods provide increasing levels of control over the way in which the sort is performed. Note: the compareTo() method does a Unicode lex.

Two constructors are provided. The first is a public noarg constructor; which should be use in routinely. The second constructor is protected and allows a boolean flag to be passsed to set verbose accordingly. It should be used for debug purposes only, as it may generate a significant amount of output to stdout.


Field Summary
private static String RESOURCE
           
private  boolean verbose
           
private static String versionID
           
 
Constructor Summary
  Sorter()
          Creates a new Sorter object using this no-arg constructor.
protected Sorter(boolean Verbose)
          Creates a new Sorter object for debugging use.
 
Method Summary
private  String[] bubble_sort(String[] a, int begin, int end, boolean ascend, boolean caseSensitive)
           
 String[] sort(String[] sarray)
          Level 1 sort method.
 String[] sort(String[] sarray, boolean ascend)
          Level 2 sort method.
 String[] sort(String[] sarray, boolean ascend, boolean caseSensitive)
          Level 3 sort method.
 String[] sort(String[] sarray, int begin, int end, boolean ascend, boolean caseSensitive)
          Level 4 sort method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionID

private static final String versionID
See Also:
Constant Field Values

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

verbose

private boolean verbose
Constructor Detail

Sorter

public Sorter()
Creates a new Sorter object using this no-arg constructor.


Sorter

protected Sorter(boolean Verbose)
Creates a new Sorter object for debugging use.

Parameters:
Verbose - set true for verbose output
Method Detail

sort

public String[] sort(String[] sarray)
              throws ArrayIndexOutOfBoundsException,
                     NullPointerException
Level 1 sort method.

This method sorts in ascending order, in a case sensitive manner, from the first to last element of the String array.

Parameters:
sarray - the String array to sort
Returns:
a sorted String array
Throws:
NullPointerException - if an element in the array is null.
ArrayIndexOutOfBoundsException

sort

public String[] sort(String[] sarray,
                     boolean ascend)
              throws ArrayIndexOutOfBoundsException,
                     NullPointerException
Level 2 sort method.

This method sorts in ascending order if ascend is true, and in descending order if ascend is false. As with the Level 1 sort, above, the sort is done in a case sensitive manner, from the first to last element of the String array.

Parameters:
sarray - the String array to sort
ascend - the sort order flag, true for ascending, false for descending
Returns:
a sorted String array
Throws:
NullPointerException - if an element in the array is null.
ArrayIndexOutOfBoundsException

sort

public String[] sort(String[] sarray,
                     boolean ascend,
                     boolean caseSensitive)
              throws ArrayIndexOutOfBoundsException,
                     NullPointerException
Level 3 sort method.

This method sorts in ascending order if ascend is true, and in descending order if ascend is false. The case of the Strings is considered in the comparisions if caseSensitive is true, and is disregarded if it is false. As with the Level 2 sort, above, the sort is done from the first to last element of the String array.

Parameters:
sarray - the String array to sort
ascend - the sort order flag, true for ascending, false for descending
caseSensitive - the flag to indicate whether the comparisions should be case sensitive
Returns:
a sorted String array
Throws:
NullPointerException - if an element in the array is null.
ArrayIndexOutOfBoundsException

sort

public String[] sort(String[] sarray,
                     int begin,
                     int end,
                     boolean ascend,
                     boolean caseSensitive)
              throws ArrayIndexOutOfBoundsException,
                     NullPointerException
Level 4 sort method.

This method sorts in ascending order if ascend is true, and in descending order if ascend is false. The case of the Strings is considered in the comparisions if caseSensitive is true, and is disregarded if it is false. The comparisions begin and end as indicated, inclusively. Except that if begin is less than end, nothing is done.

Parameters:
sarray - the String array to sort
begin - the first index
end - the last index
ascend - the sort order flag, true for ascending, false for descending
caseSensitive - the flag to indicate whether the comparisions should be case sensitive
Returns:
a sorted String array
Throws:
NullPointerException - if an element in the array is null.
ArrayIndexOutOfBoundException - if either the begin or end values is less than zero, or is greater than the size of the array.
ArrayIndexOutOfBoundsException

bubble_sort

private String[] bubble_sort(String[] a,
                             int begin,
                             int end,
                             boolean ascend,
                             boolean caseSensitive)
                      throws ArrayIndexOutOfBoundsException,
                             NullPointerException
Throws:
ArrayIndexOutOfBoundsException
NullPointerException