package Sorting; import java.time.Duration; /** * This is a class to hold the efficiencty results of a sorter. We will use this * because we can only have one return value from a method, but want to get more * than one piece of data from each sorter. * * We will write several constructors for this class, as not all sorting algorithms * will use all of the fields. For example, radix sort does not use comparisons. * Counting sort does not use swaps. * * Writing several constructors for difference situations is an example of * "polymorphism" -- the quality of object oriented design that lets a single * interface have multiple implementations. * * The methods that call the constructor of SortResult don't know it has lots of * them, they only know what data they have to give it. */ public class SortResult { private String sortType; private Integer [] sortedArray; private String comparisonsUsed; // private String swapsUsed; private Duration timeUsed; public SortResult(String st, Integer[] a, long c, Duration t){ sortType = st; sortedArray = a; if(c==0){ comparisonsUsed = "No"; } else{ comparisonsUsed = Long.toString(c); } timeUsed = t; } public SortResult(String st, Integer[] a, Duration t){ sortType = st; sortedArray = a; timeUsed = t; comparisonsUsed = "Unknown"; } public String getSortType(){ return sortType; } public Integer[] getSortedArray(){ return sortedArray; } public Duration getTimeUsed(){ return timeUsed; } public String getComparisonsUsed(){ return comparisonsUsed; } //public String getSwapsUsed(){ //return swapsUsed; //} }