forked from Labore/PR2-L
added TaschenrechnerInt-demos and some copyrights
parent
8346318513
commit
09a42c58b1
|
|
@ -4,6 +4,27 @@
|
||||||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "TaschenrechnerInt2",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "TaschenrechnerInt2",
|
||||||
|
"projectName": "PR2-L_ada963eb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "TaschenrechnerInt",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "TaschenrechnerInt",
|
||||||
|
"projectName": "PR2-L_ada963eb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "DemoParallel",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "DemoParallel",
|
||||||
|
"projectName": "PR2-L_ada963eb"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
"name": "TaschenrechnerInt4",
|
"name": "TaschenrechnerInt4",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
// Lazy Evaluation von Operationen
|
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
|
||||||
|
* W3L-Verlag Dortmund, 3. Auflage, 2014
|
||||||
|
* Lazy Evaluation von Operationen, S. 345.
|
||||||
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,32 @@
|
||||||
// Sequenzielle vs. parallele Berechnung
|
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
|
||||||
|
* W3L-Verlag Dortmund, 3. Auflage, 2014
|
||||||
|
* Sequenzielle vs. parallele Berechnung, S. 347 f.
|
||||||
|
*/
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DemoParallel {
|
public class DemoParallel {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
double uGrenze = -30.0, oGrenze = +40.0;
|
||||||
long start = System.currentTimeMillis();
|
// Bereiche der Zufallszahlen
|
||||||
|
// Liste mit 10 Mio. Daten erzeugen
|
||||||
|
List<Double> d = Stream.generate(
|
||||||
|
() -> (uGrenze + (Math.random() * (oGrenze - uGrenze + 1))))
|
||||||
|
.limit(10_000_000).collect(Collectors.toList());
|
||||||
|
|
||||||
double uGrenze = -30.0, oGrenze = +40.0;
|
long start = System.currentTimeMillis();
|
||||||
// Bereiche der Zufallszahlen
|
|
||||||
// Liste mit 10 Mio. Daten erzeugen
|
|
||||||
List<Double> d = Stream.generate(
|
|
||||||
() -> new Double(uGrenze+(Math.random() *
|
|
||||||
(oGrenze - uGrenze + 1))))
|
|
||||||
.limit(10_000_000).collect(Collectors.toList());
|
|
||||||
|
|
||||||
List<Double> temp =
|
d.stream()
|
||||||
d.stream()
|
.parallel()
|
||||||
.sorted()
|
.sorted()
|
||||||
.filter(wert -> (Math.abs(wert) > 25.0))
|
.filter(wert -> (Math.abs(wert) > 25.0))
|
||||||
.parallel()
|
.collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
long stop = System.currentTimeMillis();
|
long stop = System.currentTimeMillis();
|
||||||
System.out.println("Verbrauchte Zeit in ms: " + (stop - start));
|
|
||||||
}
|
System.out.println("Verbrauchte Zeit in ms: " + (stop - start));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||||
|
|
||||||
|
## Folder Structure
|
||||||
|
|
||||||
|
The workspace contains two folders by default, where:
|
||||||
|
|
||||||
|
- `src`: the folder to maintain sources
|
||||||
|
- `lib`: the folder to maintain dependencies
|
||||||
|
|
||||||
|
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||||
|
|
||||||
|
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||||
|
|
||||||
|
## Dependency Management
|
||||||
|
|
||||||
|
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
|
||||||
|
* W3L-Verlag Dortmund, 3. Auflage, 2014
|
||||||
|
* Funktionale Schnittstellen, S. 339
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TaschenrechnerInt
|
||||||
|
{
|
||||||
|
@FunctionalInterface
|
||||||
|
interface MathInteger
|
||||||
|
{
|
||||||
|
int berechne(int a, int b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args [])
|
||||||
|
{
|
||||||
|
MathInteger addiere = (c, d) -> c + d;
|
||||||
|
MathInteger multipliziere = (x, y) -> x * y;
|
||||||
|
|
||||||
|
System.out.println(addiere.berechne(10, 20));
|
||||||
|
System.out.println(multipliziere.berechne(10, 20));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"java.project.sourcePaths": ["src"],
|
||||||
|
"java.project.outputPath": "bin",
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
|
||||||
|
|
||||||
|
## Folder Structure
|
||||||
|
|
||||||
|
The workspace contains two folders by default, where:
|
||||||
|
|
||||||
|
- `src`: the folder to maintain sources
|
||||||
|
- `lib`: the folder to maintain dependencies
|
||||||
|
|
||||||
|
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
|
||||||
|
|
||||||
|
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
|
||||||
|
|
||||||
|
## Dependency Management
|
||||||
|
|
||||||
|
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
|
||||||
|
* W3L-Verlag Dortmund, 3. Auflage, 2014
|
||||||
|
* Funktionale Schnittstellen, S. 340
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TaschenrechnerInt2
|
||||||
|
{
|
||||||
|
@FunctionalInterface
|
||||||
|
interface MathInteger
|
||||||
|
{
|
||||||
|
int berechne(int a, int b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ergebnis(int x, int y, MathInteger op)
|
||||||
|
{
|
||||||
|
return op.berechne(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args [])
|
||||||
|
{
|
||||||
|
int c = 10, d = 20;
|
||||||
|
System.out.println(ergebnis(c, d, (c1, d1) -> c1 - d1));
|
||||||
|
System.out.println(ergebnis(c, d, (c1, d1) -> c1 / d1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
|
||||||
|
* W3L-Verlag Dortmund, 3. Auflage, 2014
|
||||||
|
* Funktionale Schnittstellen, S. 341.
|
||||||
|
*/
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface MathInteger
|
interface MathInteger
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
/**Copyright (c) Balzert, H: "Java: Objektorientiert Programmieren"
|
||||||
|
* W3L-Verlag Dortmund, 3. Auflage, 2014
|
||||||
|
* Funktionale Schnittstellen, S. 343.
|
||||||
|
*/
|
||||||
|
|
||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
import java.util.function.IntPredicate;
|
import java.util.function.IntPredicate;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue