nl.uva.vlet.util
Class QSort

java.lang.Object
  extended by nl.uva.vlet.util.QSort

public class QSort
extends java.lang.Object

Implements QuickSort, on an array of objects. An implementor of `Comparer' is passed in to compare two objects.


Nested Class Summary
static class QSort.VAttributeComparer
           
static class QSort.VNodeComparer
           
 
Constructor Summary
QSort(Comparer c)
          Create a QSort object.
 
Method Summary
 int[] sort(int[] mapping, java.lang.Object[] list, int start, int end)
          Sorts a subsequence of the array, according to the Comparer.
 int[] sort(int[] mapping, java.util.Vector list, int start, int end)
          Sorts a subsequence of the array, according to the Comparer.
 int[] sort(java.lang.Object[] list)
          Sorts the array, according to the Comparer.
 int[] sort(java.util.Vector list)
          Sorts the array, according to the Comparer.
static void sortVAttributes(VAttribute[] attrs)
           
static void sortVNodes(VNode[] nodes, boolean typeFirst, boolean ignoreCase)
          Sort by name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QSort

public QSort(Comparer c)
Create a QSort object. One way to use this would with dynamic class creation:
 
 QSort sorter = new QSort(new Comparer() 
 {
     public int compare(Object a,Object b)
     { 
         if (a.key == b.key) 
             return 0; 
         else  if (a.key < b.key) 
             return -1 
         else
             return 1; 
     } 
 }); 
 
 sorter.sort(array);
 
 

Method Detail

sort

public int[] sort(java.lang.Object[] list)
Sorts the array, according to the Comparer. The returned vector (I[]) provides mapping information about the new order. The sorted list Y[] equals to the original list X[] as follows: Y[I[i]] = X[i] Or: I[index-in-Y]=index-in-X


sort

public int[] sort(java.util.Vector list)
Sorts the array, according to the Comparer.


sort

public int[] sort(int[] mapping,
                  java.lang.Object[] list,
                  int start,
                  int end)
Sorts a subsequence of the array, according to the Comparer.


sort

public int[] sort(int[] mapping,
                  java.util.Vector list,
                  int start,
                  int end)
Sorts a subsequence of the array, according to the Comparer.


sortVAttributes

public static void sortVAttributes(VAttribute[] attrs)

sortVNodes

public static void sortVNodes(VNode[] nodes,
                              boolean typeFirst,
                              boolean ignoreCase)
Sort by name. Optionally sort by type first, then by name