FileDocCategorySizeDatePackage
Sorter.javaAPI DocGlassfish v2 API4383Fri May 04 22:34:38 BST 2007com.sun.enterprise.tools.common

Sorter

public class Sorter extends Object
author
administrator
version

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		Vector v1 = new Vector();
		//Vector v2 = new Vector();
		//Vector v3 = new Vector();

		v1.addElement("aaaa");//NOI18N
		v1.addElement("zzzz");//NOI18N
		v1.addElement("dddd");//NOI18N
		v1.addElement("ccccx");//NOI18N
		v1.addElement("cccc");//NOI18N
		v1.addElement("cccc");//NOI18N
		v1.addElement("cccc");//NOI18N
		v1.addElement("bbbb");//NOI18N

		print(v1, "****** before");//NOI18N
		sort(v1);
		print(v1, "\n******after");//NOI18N
	
private static voidmergeSort(com.sun.enterprise.tools.common.SorterObject[] arr)

		int low = 0;
		int high = arr.length;

		for (int i = low; i < high; i++)
		{
			for (int j = i; j > low &&	arr[j-1].sortName.compareTo(arr[j].sortName) > 0; j--)
			{
				swap(arr, j, j-1);
			}
		}
	
private static voidprint(java.util.Vector v, java.lang.String s)

		System.out.println(s + "\n");//NOI18N

		for(Enumeration e = v.elements(); e.hasMoreElements(); )
		{
			System.out.println("" + e.nextElement());//NOI18N
		}
	
public static voidsort(java.util.Vector v)

		if(v.size() <= 1)
			return;

		SorterObject[] arr = new SorterObject[v.size()];
		Enumeration e = v.elements();
		
		for(int i = 0 ; e.hasMoreElements() ; i++)
		{
			arr[i] = new SorterObject(e.nextElement());
		}

		mergeSort(arr);

		v.removeAllElements();

		for(int i = 0; i < arr.length; i++)
		{
			v.addElement(arr[i].obj);
		}
	
private static voidswap(com.sun.enterprise.tools.common.SorterObject[] x, int a, int b)

		SorterObject t = x[a];
		x[a] = x[b];
		x[b] = t;