import sort.AsciiTracer; import sort.Sort; import sort.SortableArray; import sort.SortableData; import sort.SortableDataStatistic; import sort.SortableDataTracer; import sort.WinTracer; /* * Created on 24 oct. 2004 * */ /** * @author baudon * */ public class TestSort { private static Sort getSort(String name) throws Exception { Sort sort = (Sort) Class.forName(name).getConstructor(null) .newInstance(null); return sort; } public static void main(String[] args) { Sort sort = null; try { sort = getSort(args[0]); } catch (Exception e) { throw new Error("Tri " + args[0] + " introuvable."); } String [] argsCopy = new String[args.length - 1]; System.arraycopy(args, 1, argsCopy, 0, args.length - 1); SortableData data = new SortableArray(argsCopy); SortableDataTracer tracer = new SortableDataTracer(data); tracer.addObserver(new WinTracer(tracer, data)); tracer.addObserver(new AsciiTracer()); SortableDataStatistic statData = new SortableDataStatistic(tracer); sort.doSort(statData); for (int j = 0; j < argsCopy.length; ++j) { System.out.print(args[j] + " "); } System.out.println(); System.out.println(statData.getCompareStat() + " compare, " + statData.getSwapStat() + " swap"); } }