package Tools;

import java.util.*;

/**
 * A sort routine and a way to get the list of keys from a Hashtable as
 * a Vector (rather than a nasty Enumeration).
 */
public class Perly {
	public static Vector sort(Vector list) {
		if (list == null) return null;

		// TODO: this is a nice, slooooow n^2 sort
		Vector newlist = new Vector();
		while (list.size()>0) {
			int i, earliesti=0;
			String earliest = null;
			for (i=0; i<list.size(); i++) {
				if (earliest==null ||
					earliest.compareTo((String) list.elementAt(i))>0) {
					earliesti = i;
					earliest = (String) list.elementAt(i);
				}
			}
			list.removeElementAt(earliesti);
			newlist.addElement(earliest);
		}
		return newlist;
	}

	public static Vector keys(Hashtable hash) {
		Enumeration e = hash.keys();
		Vector v = new Vector();
		while (e.hasMoreElements()) {
			v.addElement(e.nextElement());
		}
		return v;
	}
}
