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
2fb55ecc
Commit
2fb55ecc
authored
Apr 04, 2018
by
edmundszagars
Browse files
-Result Items can now be added to TableView
-Removing unused methods and variables
parent
315970ad
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
32 deletions
+72
-32
src/gui/MainWindow.java
src/gui/MainWindow.java
+18
-13
src/helper/ExecutionTime.java
src/helper/ExecutionTime.java
+5
-0
src/helper/Result.java
src/helper/Result.java
+23
-12
src/sorting_algorithms/BubbleSort.java
src/sorting_algorithms/BubbleSort.java
+26
-7
No files found.
src/gui/MainWindow.java
View file @
2fb55ecc
...
...
@@ -63,21 +63,21 @@ public class MainWindow extends Application {
mergeSortCheckBox
.
setText
(
"Merge sort"
);
mergeSortCheckBox
.
setSelected
(
true
);
TableColumn
<
Result
,
Double
>
dataColumn
=
new
TableColumn
(
"Data"
);
TableColumn
<
Result
,
Double
>
dataColumn
=
new
TableColumn
(
"Data"
);
dataColumn
.
setMinWidth
(
300
);
dataColumn
.
setCellValueFactory
(
new
PropertyValueFactory
<>(
"startData"
));
dataColumn
.
setCellValueFactory
(
new
PropertyValueFactory
<>(
"startData
String
"
));
TableColumn
<
Result
,
Double
>
resultDataColumn
=
new
TableColumn
(
"Result"
);
TableColumn
<
Result
,
Double
>
resultDataColumn
=
new
TableColumn
(
"Result"
);
resultDataColumn
.
setMinWidth
(
300
);
resultDataColumn
.
setCellValueFactory
(
new
PropertyValueFactory
<>(
"resultData"
));
resultDataColumn
.
setCellValueFactory
(
new
PropertyValueFactory
<>(
"resultData
String
"
));
TableColumn
<
Result
,
Long
>
timeColumn
=
new
TableColumn
(
"Time"
);
TableColumn
<
Result
,
Long
>
timeColumn
=
new
TableColumn
(
"
Execution
Time"
);
timeColumn
.
setMinWidth
(
100
);
timeColumn
.
setCellValueFactory
(
new
PropertyValueFactory
<>(
"executionResultTime"
));
table
=
new
TableView
<>();
table
.
setItems
(
getResults
(
results
));
table
.
getColumns
().
addAll
(
dataColumn
,
resultDataColumn
,
timeColumn
);
table
.
getColumns
().
addAll
(
dataColumn
,
resultDataColumn
,
timeColumn
);
Button
startButton
=
new
Button
(
"Run tests"
);
...
...
@@ -89,9 +89,17 @@ public class MainWindow extends Application {
}
catch
(
FileNotFoundException
e
)
{
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
[]
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 {
primaryStage
.
show
();
}
public
ObservableList
<
Result
>
getResults
(
ArrayList
<
Result
>
resultArrayList
){
ObservableList
<
Result
>
results
=
FXCollections
.
observableArrayList
();
results
.
add
(
new
Result
(
new
double
[]{
1
,
1
,
1
,
1
},
new
double
[]{
1
,
1
,
1
,
1
}));
results
.
addAll
(
this
.
results
);
return
results
;
public
ObservableList
<
Result
>
getResults
(
ArrayList
<
Result
>
resultArrayList
)
{
return
FXCollections
.
observableArrayList
();
}
}
src/helper/ExecutionTime.java
0 → 100644
View file @
2fb55ecc
package
helper
;
public
interface
ExecutionTime
{
long
getExecutionTime
();
}
src/helper/Result.java
View file @
2fb55ecc
package
helper
;
import
java
fx.collections.ObservableList
;
import
java
.util.Arrays
;
public
class
Result
{
private
double
[]
startData
;
private
double
[]
resultData
;
private
long
executionStartTime
;
private
long
executionEndTime
;
private
String
startDataString
;
private
String
resultDataString
;
;
private
long
executionResultTime
;
public
void
setExecutionResultTime
(
long
executionResultTime
)
{
this
.
executionResultTime
=
executionResultTime
;
}
public
long
getExecutionResultTime
()
{
return
executionResultTime
;
}
public
Result
()
{
this
.
startData
=
new
double
[]{};
this
.
resultData
=
new
double
[]{};
this
.
executionStartTime
=
0
;
this
.
executionEndTime
=
0
;
this
.
executionResultTime
=
0
;
}
public
Result
(
double
[]
startData
,
double
[]
resultData
)
{
this
.
startData
=
startData
;
this
.
resultData
=
resultData
;
executionResultTime
=
getExecutionTime
();
}
public
void
setExecutionStartTime
()
{
this
.
executionStartTime
=
System
.
currentTimeMillis
();
public
String
getStartDataString
()
{
return
startDataString
;
}
public
void
setStartDataString
(
double
[]
array
)
{
this
.
startDataString
=
Arrays
.
toString
(
array
);
}
public
void
setExecutionEndTime
()
{
this
.
executionEndTime
=
System
.
currentTimeMillis
()
;
public
String
getResultDataString
()
{
return
resultDataString
;
}
public
long
getExecutionTime
(
)
{
return
this
.
executionEndTime
-
this
.
executionStartTime
;
public
void
setResultDataString
(
double
[]
array
)
{
this
.
resultDataString
=
Arrays
.
toString
(
array
)
;
}
}
src/sorting_algorithms/BubbleSort.java
View file @
2fb55ecc
package
sorting_algorithms
;
import
helper.*
;
public
class
BubbleSort
{
private
static
Result
result
=
new
Result
();
public
class
BubbleSort
implements
ExecutionTime
{
private
long
executionStart
;
private
long
executionEnd
;
public
static
double
[]
bubbleSort
(
double
[]
array
)
{
result
.
setE
xecutionStart
Time
();
public
double
[]
bubbleSort
(
double
[]
array
)
{
e
xecutionStart
=
System
.
currentTimeMillis
();
int
n
=
array
.
length
;
int
k
;
for
(
int
m
=
n
;
m
>=
0
;
m
--)
{
...
...
@@ -16,7 +18,7 @@ public class BubbleSort {
}
}
}
result
.
setExecutionEndTime
();
executionEnd
=
System
.
currentTimeMillis
();
return
array
;
}
...
...
@@ -27,7 +29,24 @@ public class BubbleSort {
array
[
k
]
=
tmp
;
}
public
static
long
getBubbleSortExecutionResult
(){
return
result
.
getExecutionTime
();
private
long
getExecutionStart
()
{
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
();
}
}
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