Commit 96a80e9e authored by edmundszagars's avatar edmundszagars
Browse files

Changes in TebleView it now shows array size, Sort type and Execution time

parent e37c9332
......@@ -12,9 +12,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import sorting_algorithms.BubbleSort;
import sorting_algorithms.QuickSort;
import sorting_algorithms.Sortable;
import sorting_algorithms.*;
import java.io.File;
import java.io.FileNotFoundException;
......@@ -58,6 +56,7 @@ public class MainWindow extends Application {
System.out.println("Bubble selected");
sortables.add(new BubbleSort());
}else if (!bubbleSortCheckBox.isSelected()){
//TODO: Rremove item from sortables"
System.out.println("BS unselected");
}
});
......@@ -65,10 +64,22 @@ public class MainWindow extends Application {
CheckBox selectionSortCheckBox = new CheckBox();
selectionSortCheckBox.setText("Selection sort");
selectionSortCheckBox.setSelected(false);
selectionSortCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (selectionSortCheckBox.isSelected()) {
System.out.println("Selection sort selected");
sortables.add(new SelectionSort());
}
});
CheckBox insertionSortCheckBox = new CheckBox();
insertionSortCheckBox.setText("Insertion sort");
insertionSortCheckBox.setSelected(false);
insertionSortCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (insertionSortCheckBox.isSelected()) {
System.out.println("Insertion sort selected");
sortables.add(new InsertionSort());
}
});
CheckBox quickSortCheckBox = new CheckBox();
quickSortCheckBox.setText("Quick sort");
......@@ -83,17 +94,23 @@ public class MainWindow extends Application {
CheckBox mergeSortCheckBox = new CheckBox();
mergeSortCheckBox.setText("Merge sort");
mergeSortCheckBox.setSelected(false);
mergeSortCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
if (mergeSortCheckBox.isSelected()) {
System.out.println("Merge sort selected");
sortables.add(new MergeSort());
}
});
TableColumn<Result, Double> dataColumn = new TableColumn<>("Data");
TableColumn<Result, Double> dataColumn = new TableColumn<>("Sort type");
dataColumn.setMinWidth(300);
dataColumn.setCellValueFactory(new PropertyValueFactory<>("startDataString"));
dataColumn.setCellValueFactory(new PropertyValueFactory<>("sortTypeName"));
TableColumn<Result, Double> resultDataColumn = new TableColumn<>("Result");
resultDataColumn.setMinWidth(300);
resultDataColumn.setCellValueFactory(new PropertyValueFactory<>("resultDataString"));
TableColumn<Result, Double> resultDataColumn = new TableColumn<>("Array size");
resultDataColumn.setMinWidth(200);
resultDataColumn.setCellValueFactory(new PropertyValueFactory<>("arraySize"));
TableColumn<Result, Long> timeColumn = new TableColumn<>("Execution Time");
timeColumn.setMinWidth(100);
timeColumn.setMinWidth(200);
timeColumn.setCellValueFactory(new PropertyValueFactory<>("executionResultTime"));
table = new TableView<>();
......@@ -113,11 +130,13 @@ public class MainWindow extends Application {
"Please select sorting algorithm to execute test");
return;
}
GetDataFromCSV dataFromCSV = new GetDataFromCSV();
dataFromCSV.setnFileLocation(filePath);
try {
list = new ArrayList<>(dataFromCSV.getDataFromCSV());
} catch (FileNotFoundException e) {
new ErrorBox("File not found","");
e.printStackTrace();
}
for (Object aList : list) {
......@@ -125,9 +144,12 @@ public class MainWindow extends Application {
Result result = new Result();
double[] ar = dataFromCSV.getDoubleArrayFromListItem((ArrayList) aList);
sortable.sort(ar);
result.setExecutionResultTime(sortable.getExecutionEndTime());
result.setSortTypeName(sortable.getSortTypeName());
result.setArraySize(ar);
table.getItems().add(result);
System.out.println(sortable.getClass() + "\n" + Arrays.toString(ar));
//System.out.println(sortable.getClass() + "\n" + Arrays.toString(ar));
}
}
});
......@@ -148,6 +170,7 @@ public class MainWindow extends Application {
Scene mainScene = new Scene(layout, 700, 500);
primaryStage.setScene(mainScene);
primaryStage.setTitle("Sorting algorithm system");
primaryStage.show();
}
......
......@@ -5,8 +5,8 @@ import java.util.Arrays;
public class Result {
private double[] startData;
private double[] resultData;
private String startDataString;
private String resultDataString;
private String sortTypeName;
private String arraySize;
private long executionResultTime;
public Result() {
......@@ -15,25 +15,21 @@ public class Result {
this.executionResultTime = 0;
}
public Result(double[] startData, double[] resultData) {
this.startData = startData;
this.resultData = resultData;
public String getSortTypeName() {
return sortTypeName;
}
public String getStartDataString() {
return startDataString;
public void setSortTypeName(String sortTypeName) {
this.sortTypeName = sortTypeName;
}
public void setStartDataString(double[] array) {
this.startDataString = Arrays.toString(array);
public String getArraySize() {
return arraySize;
}
public String getResultDataString() {
return resultDataString;
}
public void setResultDataString(double[] array) {
this.resultDataString = Arrays.toString(array);
public void setArraySize(double[] array) {
if(array.length > 0)
this.arraySize = Integer.toString(array.length);
}
public void setExecutionResultTime(long executionResultTime) {
......
......@@ -4,8 +4,9 @@ import helper.*;
public class BubbleSort implements Sortable {
private long executionStartTime;
private long executionEndTime;
private static final String SORT_TYPE_NAME = "Bubble sort";
private long executionStartTime;
private long executionEndTime;
private static void swapNumbers(int i, int k, double[] array) {
double tmp;
......@@ -51,4 +52,9 @@ public class BubbleSort implements Sortable {
public long getExecutionEndTime() {
return executionEndTime;
}
@Override
public String getSortTypeName() {
return SORT_TYPE_NAME;
}
}
package sorting_algorithms;
public class InsertionSort implements Sortable {
private static final String SORT_TYPE_NAME = "Insertion sort";
private long executionStartTime;
private long executionEndTime;
......@@ -40,4 +41,9 @@ public class InsertionSort implements Sortable {
public long getExecutionEndTime() {
return executionEndTime;
}
@Override
public String getSortTypeName() {
return SORT_TYPE_NAME;
}
}
package sorting_algorithms;
public class MergeSort implements Sortable{
private static final String SORT_TYPE_NAME = "Merge sort";
private double[] array;
private double[] tempMergArr;
......@@ -38,6 +40,11 @@ public class MergeSort implements Sortable{
return executionEndTime;
}
@Override
public String getSortTypeName() {
return SORT_TYPE_NAME;
}
private void doMergeSort(int lowerIndex, int higherIndex) {
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
......
package sorting_algorithms;
public class QuickSort implements Sortable{
private static final String SORT_TYPE_NAME = "Quick sort";
private double array[];
private long executionStartTime;
......@@ -69,4 +71,9 @@ public class QuickSort implements Sortable{
public long getExecutionEndTime() {
return executionEndTime;
}
@Override
public String getSortTypeName() {
return SORT_TYPE_NAME;
}
}
package sorting_algorithms;
public class SelectionSort implements Sortable{
private static final String SORT_TYPE_NAME = "Selection sort";
private long executionStartTime;
private long executionEndTime;
......@@ -41,4 +43,9 @@ public class SelectionSort implements Sortable{
public long getExecutionEndTime() {
return executionEndTime;
}
@Override
public String getSortTypeName() {
return SORT_TYPE_NAME;
}
}
......@@ -7,5 +7,6 @@ public interface Sortable {
void setExecutionStartTime(long startTime);
long getExecutionStartTime();
long getExecutionEndTime();
String getSortTypeName();
}
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