|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.g11ntoolkit.sorter.Sorter
Defines a bunch of static methods for efficiently sorting arrays of Strings or other objects.
It also defines two interfaces that provide two different ways of comparing objects to be sorted.
This class is based on the Sorter.java example in the Java Examples in a Nutshell, Second Edition by David Flanagan, published by O'Reilly in September, 2000.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
See License Agreement.
| Nested Class Summary | |
static interface |
Sorter.Comparable
An alternative interface that can be used to order objects. |
static interface |
Sorter.Comparer
Defines the compare() method used to compare two objects. |
| Field Summary | |
private static Sorter.Comparer |
ascii_comparer
An internal Comparer object (created with an anonymous class that compares two ASCII string objects. |
private static Sorter.Comparer |
comparable_comparer
An internal Comparer object. |
private static java.util.logging.Logger |
log
The log used for all messages from this class. |
protected static java.util.ResourceBundle |
mrb
Message Resource Bundle. |
private static Sorter.Comparer |
token_comparer
An internal Comparer object (created with an anonymous class that compares two Token objects. |
protected static java.util.ResourceBundle |
vrb
Variables Resource Bundle. |
| Constructor Summary | |
Sorter()
|
|
| Method Summary | |
static void |
sort(java.lang.Object[] a)
Sort an array of Token objects into ascending order. |
static void |
sort(java.lang.Object[] a,
int from,
int to,
boolean up,
Sorter.Comparer c)
Sort a portion of an array of arbitrary objects using the comparison defined by a Comparer object. |
static void |
sort(java.lang.Object[] a,
java.lang.Object[] b,
int from,
int to,
boolean up,
Sorter.Comparer c)
Main sort routine. |
static void |
sort(java.lang.Object[] a,
Sorter.Comparer c)
Sort an array of arbitrary objects into ascending order using the comparison defined by a Comparer object. |
static void |
sort(Sorter.Comparable[] a)
Sort an array of Comparable objects into ascending order. |
static void |
sort(Sorter.Comparable[] a,
int from,
int to,
boolean up)
Sort a portion of an array of Comparable objects. |
static void |
sort(Sorter.Comparable[] a,
java.lang.Object[] b,
int from,
int to,
boolean up)
Sort a portion of an array of Comparable objects. |
static void |
sort(java.lang.String[] a)
Sort an array of strings into ascending order using the correct collation order for the default locale. |
static void |
sort(java.lang.String[] a,
int from,
int to,
boolean up,
boolean ignorecase)
Sort a portion of an array of strings into ascending or descending order using the collation order of the default locale. |
static void |
sort(java.lang.String[] a,
int from,
int to,
boolean up,
boolean ignorecase,
java.util.Locale locale)
Sort a portion of an array of strings. |
static void |
sortASCII(java.lang.String[] a)
Sort an array of ASCII strings into ascending order. |
static void |
sortASCII(java.lang.String[] a,
int from,
int to,
boolean up)
Sort a portion of an array of ASCII strings into ascending or descending order, depending on the argument up. |
static void |
sortASCIIIgnoreCase(java.lang.String[] a)
Sort an array of ASCII strings into ascending order ignoring case. |
static void |
sortASCIIIgnoreCase(java.lang.String[] a,
int from,
int to,
boolean up)
Sort a portion of an array of ASCII strings into either ascending or descending order ignoring case. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private static java.util.logging.Logger log
protected static java.util.ResourceBundle mrb
protected static java.util.ResourceBundle vrb
private static Sorter.Comparer ascii_comparer
Comparer object (created with an anonymous class that compares two ASCII string objects.
It is used in the sortASCII methods below.
private static Sorter.Comparer token_comparer
Comparer object (created with an anonymous class that compares two Token objects.
private static Sorter.Comparer comparable_comparer
Comparer object.
It is used to compare two Comparable objects. It is used by the sort methods below that take Comparable objects as arguments instead of arbitrary objects.
| Constructor Detail |
public Sorter()
| Method Detail |
public static void sortASCII(java.lang.String[] a)
a - a String array specifying the strings to be sorted
public static void sortASCII(java.lang.String[] a,
int from,
int to,
boolean up)
a - a String array containing the strings to be sortedfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)public static void sortASCIIIgnoreCase(java.lang.String[] a)
a - a String array specifying the strings to be sorted
public static void sortASCIIIgnoreCase(java.lang.String[] a,
int from,
int to,
boolean up)
a - a String array containing the strings to be sortedfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)public static void sort(java.lang.String[] a)
a - a String array specifying the strings to be sorted
public static void sort(java.lang.String[] a,
int from,
int to,
boolean up,
boolean ignorecase)
If the ignorecase parameter is true, treat all characters as lowercase.
a - a String array containing the strings to be sortedfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)ignorecase - a boolean specifying whether to ignore the case of the characters (TRUE) or not (FALSE)
public static void sort(java.lang.String[] a,
int from,
int to,
boolean up,
boolean ignorecase,
java.util.Locale locale)
Use the collation order of the specified locale. If the ignorecase parameter is true, treat all characters as lowercase.
a - a String array containing the strings to be sortedfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)ignorecase - a boolean specifying whether to ignore the case of the characters (TRUE) or not (FALSE)locale - a Locale specifying the locale to use for the proper ordering of the characters in the stringspublic static void sort(Sorter.Comparable[] a)
Comparable objects into ascending order.
a - a Comparable object array specifying the objects to sort
public static void sort(Sorter.Comparable[] a,
int from,
int to,
boolean up)
Comparable objects.
a - a Comparable object array specifying the objects to sortfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)
public static void sort(Sorter.Comparable[] a,
java.lang.Object[] b,
int from,
int to,
boolean up)
Re-arrange the array in exactly the same was in another array.
a - a Comparable object array specifying the objects to sortb - an object array specifying array to hold the results of the sortfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)public static void sort(java.lang.Object[] a)
Token objects into ascending order.
a - a Token object array specifying the Token objects to sort.
public static void sort(java.lang.Object[] a,
Sorter.Comparer c)
Comparer object.
a - an Object array specifying the objects to sortc - a Comparer specifying the comparison method to use
public static void sort(java.lang.Object[] a,
int from,
int to,
boolean up,
Sorter.Comparer c)
a - an Object array specifying the objects to sortfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)c - a Comparer specifying the comparison method to use
public static void sort(java.lang.Object[] a,
java.lang.Object[] b,
int from,
int to,
boolean up,
Sorter.Comparer c)
Performs a quicksort on the elements of an array between the elements specified by the from and to arguments. The c argument is used to perform comparisons between elements of the array. The elements of the array are reordered and placed in the array specified by the b argument.
a - an Object array specifying the objects to sortb - an Object array specifying the array to hold the sorted objectsfrom - an int specifying the first element of the array to be sortedto - an int specifying the last element of the array to be sortedup - a boolean specifying whether to sort the elements in ascending (TRUE) order or not (FALSE)c - a Comparer specifying the comparison method to use
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||