Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gwens committed Jan 13, 2017
0 parents commit ac88d69
Show file tree
Hide file tree
Showing 24 changed files with 1,277 additions and 0 deletions.
Binary file added 9781484224861.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -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.


46 changes: 46 additions & 0 deletions ParallelStreams/nbactions.xml
@@ -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>
30 changes: 30 additions & 0 deletions ParallelStreams/pom.xml
@@ -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>
@@ -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;
}

}
@@ -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);
}
}
@@ -0,0 +1,9 @@
package de.muellerbruehl.parallelstreams;

/**
*
* @author mmueller
*/
public interface Condition<T> {
boolean test(T t);
}
@@ -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;
}
}
@@ -0,0 +1,6 @@
package de.muellerbruehl.parallelstreams;

public enum Gender {
Male,
Female;
}
@@ -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;
}
}
@@ -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 {

}

0 comments on commit ac88d69

Please sign in to comment.