|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.photoviewer.client.util.QuickSort
Generic QuickSort (only exists because this code is attempting to be completely Java 1.1 compatible).
{
String[] s = new String[]; // 's' is later filled with content
Vector v = new Vector(); // 'v' is later filled with content
...
QuickSort q = new QuickSort();
q.sort(s); // Sort array of strings
q.sort(v); // sort vector of strings
}
{
SomeCollection m_collator = getMeACollection();
...
QuickSort q = new QuickSort(new QuickSort.Comparator()
{
java.text.Collator m_collator = java.text.Collator.getInstance();
public int compare(Object o1, Object o2)
{
Person p1 = (Person) o1;
Person p2 = (Person) o2;
return m_collator.compare(p1.getName(), p2.getName());
}
});
q.sort(m_collator, 0, m_collator.itemCount(), new QuickSort.CollectionAccessor()
{
public Object getElementAt(Object array, int index)
{
SomeCollection c = (SomeCollection) array;
return c.getItem(index);
}
public void setElementAt(Object array, int index, Object value)
{
SomeCollection c = (SomeCollection) array;
c.setItem(index, value);
}
});
}
Nested Class Summary | |
static interface |
QuickSort.CollectionAccessor
Implement this interface and pased it to the sort() method when sorting collections that are not Object[]'s or Vectors. |
static interface |
QuickSort.Comparator
Implement this inteface and pass it to the QuickSort constructor that takes a Comparator when sorting a collection of items that are not Strings. |
Constructor Summary | |
QuickSort()
Instantiate a QuickSort instance that uses the default String comparator. |
|
QuickSort(QuickSort.Comparator comparator)
Instantiate a QuickSort instance that used the passed in Comparator. |
Method Summary | |
protected void |
qsort(java.lang.Object collection,
int left,
int right)
This will handle arrays that are already sorted, and arrays with duplicate keys. |
void |
sort(java.lang.Object collection)
Sort the passed in Object[] or Vector. |
void |
sort(java.lang.Object collection,
int start,
int end)
Sort the passed range of the passed in Object[] or Vector. |
void |
sort(java.lang.Object collection,
int start,
int end,
QuickSort.CollectionAccessor col)
Sort the passed in collection, using the CollectionAccessor interface to access items in the collection. |
protected void |
swap(java.lang.Object collection,
int i,
int j)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public QuickSort(QuickSort.Comparator comparator)
comparator
- Comparator that compares two objects.public QuickSort()
Method Detail |
protected void qsort(java.lang.Object collection, int left, int right)
collection
- a collection of java.lang.Objectsleft
- left boundary of collection partitionright
- right boundary of collection partitionprotected void swap(java.lang.Object collection, int i, int j)
public void sort(java.lang.Object collection)
collection
- Object[] or Vector (or derivative of one of those).public void sort(java.lang.Object collection, int start, int end)
collection
- Object[] or Vector to sort.start
- int begin index of range to sort (0 based)end
- end index of range to sort (0 based)public void sort(java.lang.Object collection, int start, int end, QuickSort.CollectionAccessor col)
collection
- CollectionAccessor to sortstart
- int begin index of range to sort (0-based)end
- int end index of range to sort (0-based)col
- CollectionAccessor implementation to provide access to a collection
that is not a Vector or Object[].
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |