package com.hithomelabs.clients.Benchmarks;


import com.hithomelabs.princeton1.common.Apple;
import com.hithomelabs.princeton1.module5.MeasurableSort;
import com.hithomelabs.princeton1.module5.SortingMetaData;

import java.util.Comparator;
import java.util.List;

/*
* * A sorting bundle, that bundles one array and passes a copy of that array for all algorithms to sort
 */
public class Bundle<E> {

    private Sortable<E> array;
    private List<MeasurableSort<E>> algorithms;
    private Comparator<E> cmp;

    Bundle(Sortable<E> array, List<MeasurableSort<E>> algorithms){
        this.array = array;
        this.algorithms = algorithms;
    }

    Bundle (Sortable<E> array, List<MeasurableSort<E>> algorithms, Comparator<E> cmp){
        this(array, algorithms);
        if (cmp != null) this.cmp = cmp;
    }

    public void run(Comparator<E> cmp){
        for (MeasurableSort<E> sortingAlgorithm: algorithms){
            SortingMetaData metaData = new SortingMetaData();
            sortingAlgorithm.sort(array.getArray(), cmp, metaData);
            System.out.println("| " + array.getOrdering() + " | " + sortingAlgorithm + " | " + metaData.timeElapsed() + " | "  + metaData.getCompares() + " | " + metaData.getExchanges() + " |" );
        }
    }

}
