Commit 2fb55ecc authored by edmundszagars's avatar edmundszagars
Browse files

-Result Items can now be added to TableView

-Removing unused methods and variables
parent 315970ad
...@@ -63,21 +63,21 @@ public class MainWindow extends Application { ...@@ -63,21 +63,21 @@ public class MainWindow extends Application {
mergeSortCheckBox.setText("Merge sort"); mergeSortCheckBox.setText("Merge sort");
mergeSortCheckBox.setSelected(true); mergeSortCheckBox.setSelected(true);
TableColumn<Result,Double> dataColumn = new TableColumn("Data"); TableColumn<Result, Double> dataColumn = new TableColumn("Data");
dataColumn.setMinWidth(300); dataColumn.setMinWidth(300);
dataColumn.setCellValueFactory(new PropertyValueFactory<>("startData")); dataColumn.setCellValueFactory(new PropertyValueFactory<>("startDataString"));
TableColumn<Result,Double> resultDataColumn = new TableColumn("Result"); TableColumn<Result, Double> resultDataColumn = new TableColumn("Result");
resultDataColumn.setMinWidth(300); resultDataColumn.setMinWidth(300);
resultDataColumn.setCellValueFactory(new PropertyValueFactory<>("resultData")); resultDataColumn.setCellValueFactory(new PropertyValueFactory<>("resultDataString"));
TableColumn<Result,Long> timeColumn = new TableColumn("Time"); TableColumn<Result, Long> timeColumn = new TableColumn("Execution Time");
timeColumn.setMinWidth(100); timeColumn.setMinWidth(100);
timeColumn.setCellValueFactory(new PropertyValueFactory<>("executionResultTime")); timeColumn.setCellValueFactory(new PropertyValueFactory<>("executionResultTime"));
table = new TableView<>(); table = new TableView<>();
table.setItems(getResults(results)); table.setItems(getResults(results));
table.getColumns().addAll(dataColumn,resultDataColumn,timeColumn); table.getColumns().addAll(dataColumn, resultDataColumn, timeColumn);
Button startButton = new Button("Run tests"); Button startButton = new Button("Run tests");
...@@ -89,9 +89,17 @@ public class MainWindow extends Application { ...@@ -89,9 +89,17 @@ public class MainWindow extends Application {
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
if(bubbleSortCheckBox.isSelected()){ if (bubbleSortCheckBox.isSelected()) {
Result anResult = new Result();
BubbleSort bs = new BubbleSort();
double[] ar = dataFromCSV.getDoubleArrayFromListItem((ArrayList) list.get(0)); double[] ar = dataFromCSV.getDoubleArrayFromListItem((ArrayList) list.get(0));
double[] resultarr = BubbleSort.bubbleSort(ar); double[] resultArray = bs.bubbleSort(ar);
anResult.setStartDataString(ar);
anResult.setResultDataString(resultArray);
anResult.setExecutionResultTime(bs.getExecutionTime());
long free = bs.getExecutionTime();
long tt = anResult.getExecutionResultTime();
table.getItems().add(anResult);
} }
}); });
...@@ -114,10 +122,7 @@ public class MainWindow extends Application { ...@@ -114,10 +122,7 @@ public class MainWindow extends Application {
primaryStage.show(); primaryStage.show();
} }
public ObservableList<Result> getResults(ArrayList<Result> resultArrayList){ public ObservableList<Result> getResults(ArrayList<Result> resultArrayList) {
ObservableList<Result> results = FXCollections.observableArrayList(); return FXCollections.observableArrayList();
results.add(new Result(new double[]{1,1,1,1},new double[]{1,1,1,1}));
results.addAll(this.results);
return results;
} }
} }
package helper;
public interface ExecutionTime {
long getExecutionTime();
}
package helper; package helper;
import javafx.collections.ObservableList; import java.util.Arrays;
public class Result { public class Result {
private double[] startData; private double[] startData;
private double[] resultData; private double[] resultData;
private long executionStartTime; private String startDataString;
private long executionEndTime; private String resultDataString;
;
private long executionResultTime; private long executionResultTime;
public void setExecutionResultTime(long executionResultTime) {
this.executionResultTime = executionResultTime;
}
public long getExecutionResultTime() {
return executionResultTime;
}
public Result() { public Result() {
this.startData = new double[]{}; this.startData = new double[]{};
this.resultData = new double[]{}; this.resultData = new double[]{};
this.executionStartTime = 0; this.executionResultTime = 0;
this.executionEndTime = 0;
} }
public Result(double[] startData, double[] resultData) { public Result(double[] startData, double[] resultData) {
this.startData = startData; this.startData = startData;
this.resultData = resultData; this.resultData = resultData;
executionResultTime = getExecutionTime();
} }
public void setExecutionStartTime() { public String getStartDataString() {
this.executionStartTime = System.currentTimeMillis(); return startDataString;
}
public void setStartDataString(double[] array) {
this.startDataString = Arrays.toString(array);
} }
public void setExecutionEndTime() { public String getResultDataString() {
this.executionEndTime = System.currentTimeMillis(); return resultDataString;
} }
public long getExecutionTime() { public void setResultDataString(double[] array) {
return this.executionEndTime - this.executionStartTime; this.resultDataString = Arrays.toString(array);
} }
} }
package sorting_algorithms; package sorting_algorithms;
import helper.*; import helper.*;
public class BubbleSort { public class BubbleSort implements ExecutionTime {
private static Result result = new Result(); private long executionStart;
private long executionEnd;
public static double[] bubbleSort(double[] array) { public double[] bubbleSort(double[] array) {
result.setExecutionStartTime(); executionStart = System.currentTimeMillis();
int n = array.length; int n = array.length;
int k; int k;
for (int m = n; m >= 0; m--) { for (int m = n; m >= 0; m--) {
...@@ -16,7 +18,7 @@ public class BubbleSort { ...@@ -16,7 +18,7 @@ public class BubbleSort {
} }
} }
} }
result.setExecutionEndTime(); executionEnd = System.currentTimeMillis();
return array; return array;
} }
...@@ -27,7 +29,24 @@ public class BubbleSort { ...@@ -27,7 +29,24 @@ public class BubbleSort {
array[k] = tmp; array[k] = tmp;
} }
public static long getBubbleSortExecutionResult(){ private long getExecutionStart() {
return result.getExecutionTime(); return executionStart;
}
private void setExecutionStart(long executionStart) {
executionStart = executionStart;
}
private long getExecutionEnd() {
return executionEnd;
}
private void setExecutionEnd(long executionEnd) {
executionEnd = executionEnd;
}
@Override
public long getExecutionTime() {
return this.getExecutionEnd() - this.getExecutionStart();
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment