/* 0440949 Andreas van Cranenburgh <andreas@unstable.nl>
 *
 * Data structures, assignment 4
 * Benchmark of populating and depopulating different hashtables
 * */

import java.util.*;

public final class Assignment1 {
    private ArrayList <List <Integer> > lists = 
        new ArrayList <List <Integer> > ();

    public Assignment1() {
        lists.add(new ArrayList<Integer>());
        lists.add(new LinkedList<Integer>());
        lists.add(new Stack<Integer>());
        lists.add(new Vector<Integer>());
    }

    public static final void main(String[] args) {
        Assignment1 bench = new Assignment4();
        long seed = 0;

        if (args.length > 0) {
            if (args[ 0 ].equals("-s")) {
                seed = Long.parseLong(args[ 1 ]);

                if (args.length > 2) {
                    int mutations[] = new int[args.length - 2];

                    for (int i = 2; i < (args.length - 1); i++)
                        mutations[i - 2] = Integer.parseInt(args[ i ]);

                    bench.benchmark(seed, mutations);
                } else
                    bench.benchmark(seed);
            }

            else {
                int mutations[] = new int[args.length];

                for (int i = 0; i < args.length; i++)
                    mutations[i] = Integer.parseInt(args[ i ]);

                bench.benchmark(seed, mutations);
            }
        } else
            bench.benchmark();
    }

    public void benchmark(long elemGenSeed, int[] mutations) {

        for (List<Integer> list : lists) {
            ListTimer timer = new ListTimer(list, elemGenSeed);
            System.out.print(list.getClass().getSimpleName());
            System.out.print(":    ");
            System.out.println(timer.time(mutations));
        }
    }

    private static void errorExit(String msg) {
        System.out.println(msg);
        System.exit(1);
    }
}
