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 { private Sortable array; private List> algorithms; private Comparator cmp; Bundle(Sortable array, List> algorithms){ this.array = array; this.algorithms = algorithms; } Bundle (Sortable array, List> algorithms, Comparator cmp){ this(array, algorithms); if (cmp != null) this.cmp = cmp; } public void run(Comparator cmp){ for (MeasurableSort sortingAlgorithm: algorithms){ SortingMetaData metaData = new SortingMetaData(); sortingAlgorithm.sort(array.getArray(), cmp, metaData); System.out.println("| " + array.getOrdering() + " | " + sortingAlgorithm + " | " + metaData.timeElapsed() + " | " + metaData.getCompares() + " | " + metaData.getExchanges() + " |" ); } } }