Commit 98b14750 authored by edmundszagars's avatar edmundszagars
Browse files

Adding new Class to store and return results

parent 1b034e7d
package gui;
import helper.GetDataFromCSV;
import helper.Result;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
......@@ -20,7 +20,9 @@ import java.util.Arrays;
public class MainWindow extends Application {
private FileChooser fileChooser = new FileChooser();
private String filePath;
ArrayList list;
private ArrayList list;
private TableView<Result> table = new TableView();
ArrayList<Result> results = new ArrayList<>();
@Override
public void start(Stage primaryStage) {
......@@ -60,6 +62,16 @@ public class MainWindow extends Application {
mergeSortCheckBox.setText("Merge sort");
mergeSortCheckBox.setSelected(true);
TableColumn dataColumn = new TableColumn("Data");
dataColumn.setMinWidth(300);
TableColumn resultDataColumn = new TableColumn("Result");
resultDataColumn.setMinWidth(300);
TableColumn timeColumn = new TableColumn("Time");
timeColumn.setMinWidth(100);
table = new TableView<>();
table.getColumns().addAll(dataColumn,resultDataColumn,timeColumn);
Button startButton = new Button("Run tests");
startButton.setOnAction(event -> {
GetDataFromCSV dataFromCSV = new GetDataFromCSV();
......@@ -70,13 +82,12 @@ public class MainWindow extends Application {
e.printStackTrace();
}
if(bubbleSortCheckBox.isSelected()){
double[] ar = dataFromCSV.getDoubleArrayFromListItem((ArrayList) list.get(0));
System.out.println(Arrays.toString(BubbleSort.bubbleSort(ar)));
double[] resultarr = BubbleSort.bubbleSort(ar);
System.out.println("Bouble sort will be executed");
table.setItems(getResults());
}
double[] ar = dataFromCSV.getDoubleArrayFromListItem((ArrayList) list.get(0));
System.out.println(Arrays.toString(ar));
});
VBox layout = new VBox(15);
......@@ -89,11 +100,18 @@ public class MainWindow extends Application {
insertionSortCheckBox,
quickSortCheckBox,
mergeSortCheckBox,
startButton);
startButton,
table);
Scene mainScene = new Scene(layout, 700, 500);
primaryStage.setScene(mainScene);
primaryStage.show();
}
public ObservableList<Result> getResults(){
ObservableList<Result> results = FXCollections.observableArrayList();
results.add(new Result(new double[]{1,2,3},new double[]{1,2,3},BubbleSort.getBubbleSortExecutionResult()));
return results;
}
}
package helper;
import javafx.collections.ObservableList;
public class Result {
private double[] startData;
private double[] resultData;
private long executionStartTime;
private long executionEndTime;
public Result(){
this.startData = new double[]{};
this.resultData = new double[]{};
this.executionStartTime = 0;
this.executionEndTime = 0;
}
public Result(double[] startData, double[] resultData,long executionTime){
this.startData = startData;
this.resultData = resultData;
executionTime = getExecutionTime();
}
public void setExecutionStartTime() {
this.executionStartTime = System.currentTimeMillis();
}
public void setExecutionEndTime(){
this.executionEndTime = System.currentTimeMillis();
}
public long getExecutionTime(){
return this.executionEndTime - this.executionStartTime;
}
}
package sorting_algorithms;
import helper.*;
public class BubbleSort {
private static Result result = new Result();
public static double[] bubbleSort(double[] array) {
result.setExecutionStartTime();
int n = array.length;
int k;
for (int m = n; m >= 0; m--) {
......@@ -12,6 +16,7 @@ public class BubbleSort {
}
}
}
result.setExecutionEndTime();
return array;
}
......@@ -21,4 +26,8 @@ public class BubbleSort {
array[i] = array[k];
array[k] = tmp;
}
public static long getBubbleSortExecutionResult(){
return result.getExecutionTime();
}
}
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