Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Edmunds Žagars
Java_course_final
Commits
98b14750
Commit
98b14750
authored
Mar 29, 2018
by
edmundszagars
Browse files
Adding new Class to store and return results
parent
1b034e7d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
10 deletions
+72
-10
src/gui/MainWindow.java
src/gui/MainWindow.java
+28
-10
src/helper/Result.java
src/helper/Result.java
+35
-0
src/sorting_algorithms/BubbleSort.java
src/sorting_algorithms/BubbleSort.java
+9
-0
No files found.
src/gui/MainWindow.java
View file @
98b14750
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
;
}
}
src/helper/Result.java
0 → 100644
View file @
98b14750
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
;
}
}
src/sorting_algorithms/BubbleSort.java
View file @
98b14750
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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment