Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac88d69
Showing
24 changed files
with
1,277 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2016 Michael M�ller | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<actions> | ||
<action> | ||
<actionName>debug</actionName> | ||
<packagings> | ||
<packaging>jar</packaging> | ||
</packagings> | ||
<goals> | ||
<goal>process-classes</goal> | ||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> | ||
</goals> | ||
<properties> | ||
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath de.muellerbruehl.parallelstreams.StreamsDemo</exec.args> | ||
<exec.executable>java</exec.executable> | ||
<jpda.listen>true</jpda.listen> | ||
</properties> | ||
</action> | ||
<action> | ||
<actionName>run</actionName> | ||
<packagings> | ||
<packaging>jar</packaging> | ||
</packagings> | ||
<goals> | ||
<goal>process-classes</goal> | ||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> | ||
</goals> | ||
<properties> | ||
<exec.args>-classpath %classpath de.muellerbruehl.parallelstreams.StreamsDemo</exec.args> | ||
<exec.executable>java</exec.executable> | ||
</properties> | ||
</action> | ||
<action> | ||
<actionName>profile</actionName> | ||
<packagings> | ||
<packaging>jar</packaging> | ||
</packagings> | ||
<goals> | ||
<goal>process-classes</goal> | ||
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal> | ||
</goals> | ||
<properties> | ||
<exec.args>-classpath %classpath de.muellerbruehl.parallelstreams.StreamsDemo</exec.args> | ||
<exec.executable>java</exec.executable> | ||
</properties> | ||
</action> | ||
</actions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.muellerbruehl</groupId> | ||
<artifactId>ParallelStreams</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
<build> | ||
<finalName>ParallelStreams</finalName> | ||
<plugins> | ||
<!--plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>de.muellerbruehl.parallelstreams.StreamsDemo</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin--> | ||
</plugins> | ||
</build> | ||
</project> |
57 changes: 57 additions & 0 deletions
57
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/Article.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
public class Article { | ||
|
||
private final int _articleNo; | ||
private String _name; | ||
private Money _price; | ||
private int _maxSell; | ||
private int _probability; | ||
|
||
public Article(String articleData, int articleNo) { | ||
_articleNo = articleNo; | ||
try { | ||
String[] parts = articleData.split(";"); | ||
_name = parts[0]; | ||
_price = new Money(parts[1]); | ||
_maxSell = Integer.parseInt(parts[2]); | ||
_probability = Integer.parseInt(parts[3]); | ||
} catch (NumberFormatException e) { | ||
System.out.println(e.getMessage()); | ||
throw e; | ||
} | ||
} | ||
|
||
public String getName() { | ||
return _name; | ||
} | ||
|
||
public void setName(String name) { | ||
_name = name; | ||
} | ||
|
||
public Money getPrice() { | ||
return _price; | ||
} | ||
|
||
public void setPrice(Money price) { | ||
_price = price; | ||
} | ||
|
||
public int getMaxSells() { | ||
return _maxSell; | ||
} | ||
|
||
public void setMaxSell(int maxSell) { | ||
_maxSell = maxSell; | ||
} | ||
|
||
public int getProbability() { | ||
return _probability; | ||
} | ||
|
||
public void setProbability(int probability) { | ||
_probability = probability; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/ArticleInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
public class ArticleInfo { | ||
private final int _articleNo; | ||
private long _quantity; | ||
private Money _amount; | ||
|
||
public ArticleInfo (int articleNo){ | ||
_articleNo = articleNo; | ||
_amount = new Money(); | ||
} | ||
public int getArticleNo() { | ||
return _articleNo; | ||
} | ||
|
||
public long getQuantity() { | ||
return _quantity; | ||
} | ||
|
||
public void setQuantity(long quantity) { | ||
_quantity = quantity; | ||
} | ||
|
||
public Money getAmount() { | ||
return _amount; | ||
} | ||
|
||
public void setAmount(Money amount) { | ||
_amount = amount; | ||
} | ||
|
||
public void addQuantity (long quantity){ | ||
_quantity += quantity; | ||
} | ||
public void addPrice(long cents){ | ||
_amount.add(cents); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/Condition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
/** | ||
* | ||
* @author mmueller | ||
*/ | ||
public interface Condition<T> { | ||
boolean test(T t); | ||
} |
75 changes: 75 additions & 0 deletions
75
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/DataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class DataProvider { | ||
|
||
private static final DataProvider _instance = new DataProvider(); | ||
private List<String> _surNames = new ArrayList<>(); | ||
private final Map<String, Gender> _givenNames = new HashMap<>(); | ||
private final Map<Integer, Article> _articles = new HashMap<>(); | ||
|
||
public static DataProvider getInstance() { | ||
return _instance; | ||
} | ||
|
||
private DataProvider() { | ||
init(); | ||
} | ||
|
||
public List<String> getSurNames() { | ||
return _surNames; | ||
} | ||
|
||
public Map<String, Gender> getGivenNames() { | ||
return _givenNames; | ||
} | ||
|
||
public Map<Integer, Article> getArticles() { | ||
return _articles; | ||
} | ||
|
||
private void init() { | ||
try { | ||
_surNames = readFile("Surnames.csv"); | ||
readFile("GivenNamesFemale.csv").stream().forEach(n -> _givenNames.put(n, Gender.Female)); | ||
readFile("GivenNamesMale.csv").stream().forEach(n -> _givenNames.put(n, Gender.Male)); | ||
int articleNo = 0; | ||
for (String line : readFile("Articles.csv")) { | ||
if (!line.trim().isEmpty()) { | ||
articleNo++; | ||
Article article = new Article(line, articleNo); | ||
_articles.put(articleNo, article); | ||
} | ||
}; | ||
} catch (IOException ex) { | ||
Logger.getLogger(DataProvider.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
} | ||
|
||
private List<String> readFile(String fileName) throws IOException { | ||
List<String> lines = new ArrayList<>(); | ||
try (InputStream is = getClass().getResourceAsStream(fileName); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
lines.add(line); | ||
} | ||
} | ||
return lines; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/Gender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
public enum Gender { | ||
Male, | ||
Female; | ||
} |
41 changes: 41 additions & 0 deletions
41
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/Money.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
public class Money { | ||
|
||
private long _cents; | ||
|
||
Money() { | ||
_cents = 0; | ||
} | ||
|
||
Money(String value) { | ||
setValue(value); | ||
} | ||
|
||
public long getCents() { | ||
return _cents; | ||
} | ||
|
||
public void setCents(long cents) { | ||
_cents = cents; | ||
} | ||
|
||
public String getValue() { | ||
return _cents / 100 + "." + _cents % 100; | ||
} | ||
|
||
public void setValue(String value) { | ||
int pos = value.indexOf("."); | ||
if (pos == -1) { | ||
_cents = 100 * Long.parseLong(value); | ||
} else { | ||
_cents = 100 * Long.parseLong(value.substring(0, pos)); | ||
String decimals = value.substring(pos + 1) + "00"; | ||
_cents += Long.parseLong(decimals.substring(0, 2)); | ||
} | ||
} | ||
|
||
public void add (long cents){ | ||
_cents += cents; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
ParallelStreams/src/main/java/de/muellerbruehl/parallelstreams/NewInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package de.muellerbruehl.parallelstreams; | ||
|
||
/** | ||
* | ||
* @author mmueller | ||
*/ | ||
public interface NewInterface { | ||
|
||
} |
Oops, something went wrong.