formatting time output
This commit is contained in:
@@ -169,7 +169,7 @@ public class AlgorithmTester{
|
|||||||
System.out.println("\n"+e.getSortType()+" sort took:");
|
System.out.println("\n"+e.getSortType()+" sort took:");
|
||||||
System.out.println(e.getComparisonsUsed()+" comparisons");
|
System.out.println(e.getComparisonsUsed()+" comparisons");
|
||||||
System.out.println(e.getWritesUsed()+" write operations");
|
System.out.println(e.getWritesUsed()+" write operations");
|
||||||
System.out.println(e.getTimeUsed().toMillis()+" milliseconds");
|
System.out.println(e.getTimeUsed()+" milliseconds");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package Sorting;
|
package Sorting;
|
||||||
|
|
||||||
import java.time.Duration;
|
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
|
* 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
|
* because we can only have one return value from a method, but want to get more
|
||||||
@@ -23,25 +25,27 @@ public class SortResult {
|
|||||||
private Integer [] sortedArray;
|
private Integer [] sortedArray;
|
||||||
private String comparisonsUsed;
|
private String comparisonsUsed;
|
||||||
private String writesUsed;
|
private String writesUsed;
|
||||||
private Duration timeUsed;
|
private String timeUsed;
|
||||||
|
|
||||||
public SortResult(String st, Integer[] a, long c, long w, Duration t){
|
public SortResult(String st, Integer[] a, long c, long w, Duration t){
|
||||||
sortType = st;
|
sortType = st;
|
||||||
sortedArray = a;
|
sortedArray = a;
|
||||||
|
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||||
if(c==0){
|
if(c==0){
|
||||||
comparisonsUsed = "No";
|
comparisonsUsed = "No";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
comparisonsUsed = Long.toString(c);
|
comparisonsUsed = nf.format(c);
|
||||||
}
|
}
|
||||||
writesUsed = Long.toString(w)
|
writesUsed = nf.format(w);
|
||||||
timeUsed = t;
|
timeUsed = nf.format(t.toMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortResult(String st, Integer[] a, Duration t){
|
public SortResult(String st, Integer[] a, Duration t){
|
||||||
sortType = st;
|
sortType = st;
|
||||||
sortedArray = a;
|
sortedArray = a;
|
||||||
timeUsed = t;
|
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||||
|
timeUsed = nf.format(t.toMillis());
|
||||||
comparisonsUsed = "Unknown";
|
comparisonsUsed = "Unknown";
|
||||||
writesUsed = "Unknown";
|
writesUsed = "Unknown";
|
||||||
}
|
}
|
||||||
@@ -54,7 +58,7 @@ public class SortResult {
|
|||||||
return sortedArray;
|
return sortedArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Duration getTimeUsed(){
|
public String getTimeUsed(){
|
||||||
return timeUsed;
|
return timeUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user