Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Simeon Christoffersen
test2021
Commits
2fa3717b
Commit
2fa3717b
authored
Sep 09, 2021
by
Simeon Christoffersen
Browse files
initial commit
parent
770a29ad
Changes
25
Hide whitespace changes
Inline
Side-by-side
javafx-template/.project
deleted
100644 → 0
View file @
770a29ad
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
javafx-template
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>
org.eclipse.m2e.core.maven2Builder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
<nature>
org.eclipse.m2e.core.maven2Nature
</nature>
</natures>
<filteredResources>
<filter>
<id>
1631170920238
</id>
<name></name>
<type>
30
</type>
<matcher>
<id>
org.eclipse.core.resources.regexFilterMatcher
</id>
<arguments>
node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
javafx-template/bin/.project
deleted
100644 → 0
View file @
770a29ad
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
javafx-template
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>
org.eclipse.m2e.core.maven2Builder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
<nature>
org.eclipse.m2e.core.maven2Nature
</nature>
</natures>
<filteredResources>
<filter>
<id>
1631170920238
</id>
<name></name>
<type>
30
</type>
<matcher>
<id>
org.eclipse.core.resources.regexFilterMatcher
</id>
<arguments>
node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
modules-template/.gitignore
deleted
100644 → 0
View file @
770a29ad
# ignore maven build folder
target/
# pom-derived eclipse jdt files
.project
.classpath
org.eclipse.*.prefs
modules-template/core/pom.xml
deleted
100644 → 0
View file @
770a29ad
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
it1901
</groupId>
<artifactId>
modules-core
</artifactId>
<parent>
<groupId>
it1901
</groupId>
<artifactId>
modules-template
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<relativePath>
..
</relativePath>
</parent>
<dependencies>
<!-- junit testing with jupiter -->
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-params
</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
modules-template/core/src/main/java/core/Calc.java
deleted
100644 → 0
View file @
770a29ad
package
core
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.function.BinaryOperator
;
import
java.util.function.UnaryOperator
;
public
class
Calc
{
private
final
List
<
Double
>
operandStack
;
public
Calc
(
double
...
operands
)
{
operandStack
=
new
ArrayList
<>(
operands
.
length
+
2
);
for
(
var
d
:
operands
)
{
operandStack
.
add
(
d
);
}
}
/**
* @return the number of operands on the stack
*/
public
int
getOperandCount
()
{
return
operandStack
.
size
();
}
/**
* Pushes a new operand onto top of the stack.
* @param d the new operand
*/
public
void
pushOperand
(
double
d
)
{
operandStack
.
add
(
d
);
}
/**
* @param n the place (from the top) to peek
* @return the n'th operand from the top
* @throws IllegalArgumentException if n is larger than the operand count
*/
public
double
peekOperand
(
int
n
)
{
if
(
n
>=
getOperandCount
())
{
throw
new
IllegalArgumentException
(
"Cannot peek at position "
+
n
+
" when the operand count is "
+
getOperandCount
());
}
return
operandStack
.
get
(
getOperandCount
()
-
n
-
1
);
}
/**
* @return the top operand
*/
public
double
peekOperand
()
{
return
peekOperand
(
0
);
}
/**
* Removes and returns the top operand.
* @return the top operand
* @throws IllegalStateException if the stack is empty
*/
public
double
popOperand
()
{
if
(
getOperandCount
()
==
0
)
{
throw
new
IllegalStateException
(
"Cannot pop from an empty stack"
);
}
return
operandStack
.
remove
(
operandStack
.
size
()
-
1
);
}
/**
* Performs the provided operation in the top operand, and
* replaces it with the result.
* @param op the operation to perform
* @return the result of performing the operation
* @throws IllegalStateException if the operand stack is empty
*/
public
double
performOperation
(
UnaryOperator
<
Double
>
op
)
throws
IllegalStateException
{
// TODO
return
0.0
;
}
/**
* Performs the provided operation in the two topmost operands, and
* replaces them with the result.
* @param op the operation to perform
* @return the result of performing the operation
* @throws IllegalStateException if the operand count is less than two
*/
public
double
performOperation
(
BinaryOperator
<
Double
>
op
)
throws
IllegalStateException
{
if
(
getOperandCount
()
<
2
)
{
throw
new
IllegalStateException
(
"Too few operands ("
+
getOperandCount
()
+
") on the stack"
);
}
var
op2
=
popOperand
();
var
op1
=
popOperand
();
var
result
=
op
.
apply
(
op1
,
op2
);
pushOperand
(
result
);
return
result
;
}
/**
* Swaps the two topmost operands.
*
* @throws IllegalStateException if the operand count is less than two
*/
public
void
swap
()
{
// TODO
}
/**
* Duplicates the top operand.
*
* @throws IllegalStateException if the operand stack is empty
*/
public
void
dup
()
{
// TODO
}
}
\ No newline at end of file
modules-template/core/src/main/java/module-info.java
deleted
100644 → 0
View file @
770a29ad
module
calc
.
core
{
exports
core
;
}
modules-template/core/src/test/java/core/CalcTest.java
deleted
100644 → 0
View file @
770a29ad
package
core
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
public
class
CalcTest
{
private
static
void
checkCalc
(
Calc
calc
,
double
...
operands
)
{
Assertions
.
assertEquals
(
operands
.
length
,
calc
.
getOperandCount
(),
"Wrong operand count"
);
for
(
int
i
=
0
;
i
<
operands
.
length
;
i
++)
{
Assertions
.
assertEquals
(
operands
[
i
],
calc
.
peekOperand
(
i
),
"Wrong value at #"
+
i
+
" of operand stack"
);
}
}
@Test
public
void
testCalc
()
{
checkCalc
(
new
Calc
());
checkCalc
(
new
Calc
(
1.0
),
1.0
);
checkCalc
(
new
Calc
(
3.14
,
1.0
),
1.0
,
3.14
);
}
@Test
public
void
testPushOperand
()
{
Calc
calc
=
new
Calc
();
calc
.
pushOperand
(
1.0
);
checkCalc
(
calc
,
1.0
);
calc
.
pushOperand
(
3.14
);
checkCalc
(
calc
,
3.14
,
1.0
);
}
@Test
public
void
testPeekOperand
()
{
Calc
calc
=
new
Calc
(
1.0
,
3.14
);
Assertions
.
assertEquals
(
3.14
,
calc
.
peekOperand
());
Assertions
.
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Calc
().
peekOperand
());
}
@Test
public
void
testPeekOperandN
()
{
Calc
calc
=
new
Calc
(
1.0
,
3.14
);
Assertions
.
assertEquals
(
3.14
,
calc
.
peekOperand
(
0
));
Assertions
.
assertEquals
(
1.0
,
calc
.
peekOperand
(
1
));
Assertions
.
assertThrows
(
IllegalArgumentException
.
class
,
()
->
calc
.
peekOperand
(
2
));
}
@Test
public
void
testPopOperand
()
{
Calc
calc
=
new
Calc
(
1.0
,
3.14
);
Assertions
.
assertEquals
(
3.14
,
calc
.
popOperand
());
checkCalc
(
calc
,
1.0
);
Assertions
.
assertEquals
(
1.0
,
calc
.
popOperand
());
checkCalc
(
calc
);
}
@Test
public
void
testPopOperand_emptyStack
()
{
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
().
popOperand
());
}
@Test
public
void
testPerformOperation1
()
{
Calc
calc
=
new
Calc
(
1.0
);
Assertions
.
assertEquals
(-
1.0
,
calc
.
performOperation
(
n
->
-
n
));
checkCalc
(
calc
,
-
1.0
);
}
@Test
public
void
testPerformOperation1_emptyOperandStack
()
{
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
().
performOperation
(
n
->
-
n
));
}
@Test
public
void
testPerformOperation2
()
{
Calc
calc
=
new
Calc
(
1.0
,
3.0
);
Assertions
.
assertEquals
(-
2.0
,
calc
.
performOperation
((
n1
,
n2
)
->
n1
-
n2
));
checkCalc
(
calc
,
-
2.0
);
}
@Test
public
void
testPerformOperation2_lessThanTwoOperands
()
{
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
(
1.0
).
performOperation
((
n1
,
n2
)
->
n1
-
n2
));
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
().
performOperation
((
n1
,
n2
)
->
n1
-
n2
));
}
@Test
public
void
testSwap
()
{
Calc
calc
=
new
Calc
(
1.0
,
3.14
);
checkCalc
(
calc
,
3.14
,
1.0
);
calc
.
swap
();
checkCalc
(
calc
,
1.0
,
3.14
);
calc
.
swap
();
checkCalc
(
calc
,
3.14
,
1.0
);
}
@Test
public
void
testSwap_lessThanTwoOperands
()
{
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
(
1.0
).
swap
());
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
().
swap
());
}
@Test
public
void
testDup
()
{
Calc
calc
=
new
Calc
(
1.0
,
3.14
);
Assertions
.
assertEquals
(
3.14
,
calc
.
popOperand
());
checkCalc
(
calc
,
1.0
);
Assertions
.
assertEquals
(
1.0
,
calc
.
popOperand
());
checkCalc
(
calc
);
}
@Test
public
void
testDup_emptyOperandStack
()
{
Assertions
.
assertThrows
(
IllegalStateException
.
class
,
()
->
new
Calc
().
dup
());
}
}
modules-template/pom.xml
deleted
100644 → 0
View file @
770a29ad
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
it1901
</groupId>
<artifactId>
modules-template
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<packaging>
pom
</packaging>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
16
</maven.compiler.source>
<maven.compiler.target>
16
</maven.compiler.target>
<skipTests>
false
</skipTests>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-api
</artifactId>
<version>
5.7.2
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
<version>
5.7.2
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-params
</artifactId>
<version>
5.7.2
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.1
</version>
<configuration>
<release>
16
</release>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
3.0.0-M5
</version>
<configuration>
<skipTests>
${skipTests}
</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>
core
</module>
<module>
ui
</module>
</modules>
</project>
modules-template/ui/pom.xml
deleted
100644 → 0
View file @
770a29ad
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
modules-ui
</artifactId>
<parent>
<groupId>
it1901
</groupId>
<artifactId>
modules-template
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<relativePath>
..
</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>
it1901
</groupId>
<artifactId>
modules-core
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
</dependency>
<!-- javafx -->
<dependency>
<groupId>
org.openjfx
</groupId>
<artifactId>
javafx-controls
</artifactId>
<version>
16
</version>
</dependency>
<dependency>
<groupId>
org.openjfx
</groupId>
<artifactId>
javafx-fxml
</artifactId>
<version>
16
</version>
</dependency>
<!-- junit testing with jupiter -->
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-engine
</artifactId>
</dependency>
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter-params
</artifactId>
</dependency>
<!-- test javafx with TextFX -->
<dependency>
<groupId>
org.testfx
</groupId>
<artifactId>
testfx-core
</artifactId>
<version>
4.0.16-alpha
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.testfx
</groupId>
<artifactId>
testfx-junit5
</artifactId>
<version>
4.0.16-alpha
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.hamcrest
</groupId>
<artifactId>
hamcrest
</artifactId>
<version>
2.2
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<configuration>
<argLine>
--add-opens calc.ui/ui=ALL-UNNAMED --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>
org.openjfx
</groupId>
<artifactId>
javafx-maven-plugin
</artifactId>
<version>
0.0.6
</version>
<!-- Default configuration for running -->
<!-- Usage: mvn javafx:run -->
<configuration>
<!-- syntax: module-name/full-app-class-name -->
<mainClass>
calc.ui/ui.App
</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
modules-template/ui/src/main/java/module-info.java
deleted
100644 → 0
View file @
770a29ad
module
calc
.
ui
{
requires
calc
.
core
;
requires
javafx
.
controls
;
requires
javafx
.
fxml
;
opens
ui
to
javafx
.
graphics
,
javafx
.
fxml
;
}
modules-template/ui/src/main/java/ui/App.java
deleted
100644 → 0
View file @
770a29ad
package
ui
;
import
javafx.application.Application
;
import
javafx.fxml.FXMLLoader
;
import
javafx.scene.Parent
;
import
javafx.scene.Scene
;
import
javafx.stage.Stage
;
import
java.io.IOException
;
/**
* JavaFX App
*/
public
class
App
extends
Application
{
@Override
public
void
start
(
Stage
stage
)
throws
IOException
{
FXMLLoader
fxmlLoader
=
new
FXMLLoader
(
this
.
getClass
().
getResource
(
"App.fxml"
));
Parent
parent
=
fxmlLoader
.
load
();
stage
.
setScene
(
new
Scene
(
parent
));
stage
.
show
();
}
public
static
void
main
(
String
[]
args
)
{
launch
();
}
}
\ No newline at end of file
modules-template/ui/src/main/java/ui/AppController.java
deleted
100644 → 0
View file @
770a29ad
package
ui
;
import
core.Calc
;
import
java.util.List
;
import
java.util.function.BinaryOperator
;
import
java.util.function.UnaryOperator
;
import
javafx.event.ActionEvent
;
import
javafx.fxml.FXML
;
import
javafx.scene.control.Label
;
import
javafx.scene.control.Labeled
;
import
javafx.scene.control.ListView
;
public
class
AppController
{
private
Calc
calc
;
public
AppController
()
{
calc
=
new
Calc
(
0.0
,
0.0
,
0.0
);
}
public
Calc
getCalc
()
{
return
calc
;
}
public
void
setCalc
(
Calc
calc
)
{
this
.
calc
=
calc
;
updateOperandsView
();
}
@FXML
private
ListView
<
Double
>
operandsView
;
@FXML
private
Label
operandView
;
@FXML
void
initialize
()
{
updateOperandsView
();
}
private
void
updateOperandsView
()
{
List
<
Double
>
operands
=
operandsView
.
getItems
();
operands
.
clear
();
int
elementCount
=
Math
.
min
(
calc
.
getOperandCount
(),
3
);
for
(
int
i
=
0
;
i
<
elementCount
;
i
++)
{
operands
.
add
(
calc
.
peekOperand
(
elementCount
-
i
-
1
));