refactor to use polymorphism
This commit is contained in:
@@ -23,6 +23,7 @@ public class SortResult {
|
||||
|
||||
private String sortType;
|
||||
private Integer [] sortedArray;
|
||||
private String[] sortedWordArray;
|
||||
private String comparisonsUsed;
|
||||
private String writesUsed;
|
||||
private String timeUsed;
|
||||
@@ -41,6 +42,21 @@ public class SortResult {
|
||||
timeUsed = nf.format(t.toMillis());
|
||||
}
|
||||
|
||||
public SortResult(String st, String[] a, long c, long w, Duration t){
|
||||
sortType = st;
|
||||
sortedWordArray = 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;
|
||||
@@ -54,10 +70,14 @@ public class SortResult {
|
||||
return sortType;
|
||||
}
|
||||
|
||||
public Integer[] getSortedArray(){
|
||||
public Integer[] getSortedNumbers(){
|
||||
return sortedArray;
|
||||
}
|
||||
|
||||
public String[] getSortedWords(){
|
||||
return sortedWordArray;
|
||||
}
|
||||
|
||||
public String getTimeUsed(){
|
||||
return timeUsed;
|
||||
}
|
||||
@@ -72,7 +92,7 @@ public class SortResult {
|
||||
|
||||
public String getSortCount(){
|
||||
NumberFormat nf = NumberFormat.getInstance(Locale.US);
|
||||
return nf.format(sortedArray.length);
|
||||
return nf.format(sortedWordArray.length);
|
||||
}
|
||||
|
||||
public String getMin(){
|
||||
@@ -85,4 +105,12 @@ public class SortResult {
|
||||
return nf.format(sortedArray[sortedArray.length-1]);
|
||||
}
|
||||
|
||||
public String getFirst(){
|
||||
return sortedWordArray[0];
|
||||
}
|
||||
|
||||
public String getLast(){
|
||||
return sortedWordArray[sortedWordArray.length-1];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user