package Sorting;

import java.time.Duration;
import java.util.Locale;
import java.text.NumberFormat;
/**
 * 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 writesUsed;
    private String timeUsed;

    public SortResult(String st, Integer[] a, long c, long w, Duration t){
        sortType = st;
        sortedArray = a;
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        if(c==0){
            comparisonsUsed = "No";
        }
        else{
        comparisonsUsed = nf.format(c);
        }
        writesUsed = nf.format(w);
        timeUsed = nf.format(t.toMillis());
    }

    public SortResult(String st, Integer[] a, Duration t){
        sortType = st;
        sortedArray = a;
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        timeUsed = nf.format(t.toMillis());
        comparisonsUsed = "Unknown";
        writesUsed = "Unknown";
    }

    public String getSortType(){
        return sortType;
    }

    public Integer[] getSortedArray(){
        return sortedArray;
    }

    public String getTimeUsed(){
        return timeUsed;
    }

    public String getComparisonsUsed(){
        return comparisonsUsed;
    }

    public String getWritesUsed(){
        return writesUsed;
    }

}