|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.sysadm.Sorter
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 |
private static final String versionID
private static final String RESOURCE
private boolean verbose
Constructor Detail |
public Sorter()
protected Sorter(boolean Verbose)
Verbose
- set true for verbose outputMethod Detail |
public String[] sort(String[] sarray) throws ArrayIndexOutOfBoundsException, NullPointerException
This method sorts in ascending order, in a case sensitive manner, from the first to last element of the String array.
sarray
- the String array to sort
NullPointerException
- if an element in the array
is null
.
ArrayIndexOutOfBoundsException
public String[] sort(String[] sarray, boolean ascend) throws ArrayIndexOutOfBoundsException, NullPointerException
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.
sarray
- the String array to sortascend
- the sort order flag, true for ascending,
false for descending
NullPointerException
- if an element in the array
is null
.
ArrayIndexOutOfBoundsException
public String[] sort(String[] sarray, boolean ascend, boolean caseSensitive) throws ArrayIndexOutOfBoundsException, NullPointerException
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.
sarray
- the String array to sortascend
- the sort order flag, true for ascending,
false for descendingcaseSensitive
- the flag to indicate whether the comparisions
should be case sensitive
NullPointerException
- if an element in the array
is null
.
ArrayIndexOutOfBoundsException
public String[] sort(String[] sarray, int begin, int end, boolean ascend, boolean caseSensitive) throws ArrayIndexOutOfBoundsException, NullPointerException
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.
sarray
- the String array to sortbegin
- the first indexend
- the last indexascend
- the sort order flag, true for ascending,
false for descendingcaseSensitive
- the flag to indicate whether the comparisions
should be case sensitive
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
private String[] bubble_sort(String[] a, int begin, int end, boolean ascend, boolean caseSensitive) throws ArrayIndexOutOfBoundsException, NullPointerException
ArrayIndexOutOfBoundsException
NullPointerException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |