Commits

RapidPM committed 60fe541

first code added

Comments (0)

Files changed (33)

                 <scope>compile</scope>
             </dependency>
 
-            <dependency>
-                <groupId>com.oracle.javafx</groupId>
-                <artifactId>javafx</artifactId>
-                <version>2.2</version>
-                <systemPath>${fx.home}/jfxrt.jar</systemPath>
-                <scope>system</scope>
-            </dependency>
-
             <!-- Weld Container -->
             <dependency>
                 <groupId>org.jboss.weld</groupId>

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_1/CHAP_1_1.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_1;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.model.Pair;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.PairListGenerator;
+
+/**
+ * Created by Sven Ruppert on 13.11.13.
+ */
+public class CHAP_1_1 {
+    public static void main(String[] args) {
+
+        final List<Pair> generateDemoValues = new PairListGenerator(){}.generateDemoValues();
+
+        //Stream from Values
+        final Stream<Pair> fromValues = Stream.of(new Pair(), new Pair());
+
+        //Stream from Array
+        final Pair[] pairs = {new Pair(), new Pair()};
+        final Stream<Pair> fromArray = Stream.of(pairs);
+
+        //Stream from List
+        final Stream<Pair> fromList = generateDemoValues.stream();
+
+        //Stream from String
+        final Stream<String> abc = Stream.of("ABC");
+        final Stream<IntStream> of = Stream.of("ABC".chars());
+        final Stream<String> splitOf = Stream.of("A,B,C".split(","));
+
+        //Stream from builder
+        final Stream<Pair> builderPairStream = Stream.<Pair>builder().add(new Pair()).build();
+
+
+        //Stream to Array
+        final Pair[] toArray = generateDemoValues.stream().toArray(Pair[]::new);
+        //Stream to List
+        final List<Pair> toList = generateDemoValues.stream().collect(Collectors.toList());
+
+        //Stream to Set
+        final Set<Pair> toSet = generateDemoValues.stream().collect(Collectors.toSet());
+
+        //Stream to Map
+        final Map<Integer,List<Pair>> collectedToMap = generateDemoValues.stream().collect(Collectors.groupingBy(Pair::getId));
+        System.out.println("collectedToMap.size() = " + collectedToMap.size());
+
+        for (final Map.Entry<Integer, List<Pair>> entry : collectedToMap.entrySet()) {
+            System.out.println("entry = " + entry);
+        }
+
+    }
+
+
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_1.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.List;
+import java.util.function.Consumer;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.model.Pair;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.PairListGenerator;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_1 {
+    public static void main(String[] args) {
+        final List<Pair> generateDemoValues = new PairListGenerator(){}.generateDemoValues();
+
+        //pre JDK8
+        for (final Pair generateDemoValue : generateDemoValues) {
+            System.out.println(generateDemoValue);
+        }
+
+        //long version
+        generateDemoValues.stream().forEach(v -> System.out.println(v) );
+
+        //short version
+        generateDemoValues.stream().forEach(System.out::println);
+        generateDemoValues.parallelStream().forEach(System.out::println);
+
+
+        generateDemoValues.stream().forEachOrdered(System.out::println);
+        generateDemoValues.parallelStream().forEachOrdered(System.out::println);
+
+
+        final Consumer<? super Pair> consumer = System.out::println;
+        generateDemoValues.stream().forEachOrdered(consumer);
+        generateDemoValues.parallelStream().forEachOrdered(consumer);
+
+    }
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_10.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_10 {
+    public static void main(String[] args) {
+        final List<Integer> demoValues
+                = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+        System.out.println(demoValues.stream()  //seriell
+                .map((m1) -> m1)
+                .parallel()
+                .map((m2) -> m2)
+                .sequential() //seriell
+                .collect(Collectors.toList()));
+
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_2.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Base64;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.model.Pair;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.PairListGenerator;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_2 {
+    public static void main(String[] args) {
+        final List<Pair> generateDemoValues = new PairListGenerator(){}.generateDemoValues();
+
+        //map from Point to DemoElements
+        final Stream<DemoElement> demoElementStream = generateDemoValues.stream().map(v -> {
+            final String value = v.getValue();
+            final DemoElement d = new DemoElement();
+            d.setDatum(new Date());
+            d.setValue(Base64.getEncoder().encodeToString(value.getBytes()));
+            return d;
+        });
+
+        final Stream<String> stringStream = demoElementStream.map(v -> v.getValue());
+        final Stream<String> stringStreamShort = demoElementStream.map(DemoElement::getValue);
+
+        //map from Point to DemoElements to Strings
+        final List<String> stringList = generateDemoValues.stream().map(v -> {
+            final String value = v.getValue();
+            final DemoElement d = new DemoElement();
+            d.setDatum(new Date());
+            d.setValue(Base64.getEncoder().encodeToString(value.getBytes()));
+            return d;
+        }).map(DemoElement::getValue).collect(Collectors.toList());
+
+        final Stream<Pair> filteredPairStream = generateDemoValues.stream().filter(v -> v.getId() % 2 == 0);
+
+
+
+
+
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_3.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Base64;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.model.Pair;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.PairListGenerator;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_3 {
+
+    public static void main(String[] args) {
+        final List<Pair> generateDemoValues = new PairListGenerator(){}.generateDemoValues();
+
+
+        //map from Point to DemoElements
+        final Stream<DemoElement> demoElementStream = generateDemoValues.stream().map(v -> {
+            final String value = v.getValue();
+            final DemoElement d = new DemoElement();
+            d.setDatum(new Date());
+            d.setValue(Base64.getEncoder().encodeToString(value.getBytes()));
+            return d;
+        });
+
+
+        final Stream<Pair> filteredPairStream = generateDemoValues.stream().filter(v -> v.getId() % 2 == 0);
+
+
+
+
+
+
+    }
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_4.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_4 {
+    public static void main(String[] args) {
+
+        final List<String> demoValues = Arrays.asList("AB", "AAB", "AAAB", "AAAAB", "AAAAAB");
+
+        final Optional<String> first = demoValues.stream().findFirst();
+
+        //intro Optional
+        final boolean present = first.isPresent();
+        System.out.println("present = " + present);
+
+        //how to create an Optional
+        final Optional<String> optionalA = Optional.of("A");
+        final Optional<String> optionalB1 = Optional.ofNullable("B");
+        final Optional<String> optionalB2 = Optional.ofNullable(null);
+        System.out.println("optionalB2.isPresent() = " + optionalB2.isPresent());
+
+        optionalA.ifPresent(System.out::println); // result = 'A'
+
+        //lambda is not activated
+        optionalB2.ifPresent(System.out::println);// result = ''
+
+        optionalA.filter(v->v.contains("A")).ifPresent(System.out::println);
+
+        demoValues.stream()
+                .forEach(v -> {
+                    Optional.ofNullable(v)
+                            .filter(o -> o.contains("AAA"))
+                            .ifPresent(System.out::println);
+                });
+
+        final Optional<String> aa = demoValues.stream()
+                .filter(v -> v.contains("AA"))
+                .findFirst();
+        System.out.println("aa = " + aa);
+
+        demoValues.stream()
+                .forEach(v -> {
+                    Optional.ofNullable(v)
+                            .map(o->o.concat("_X"))
+                            .filter(f->f.contains("AAA"))
+                            .ifPresent(System.out::println);
+                });
+
+        final Optional<Optional<String>> map = optionalA.map(CHAP_1_2_4::addX);
+        final Optional<String> flatMap = optionalA.flatMap(CHAP_1_2_4::addX);
+
+        demoValues.stream()
+                .forEach(v -> {
+                    Optional.ofNullable(v)
+                            .flatMap(CHAP_1_2_4::addX)
+                            .filter(f -> f.contains("AAA"))
+                            .ifPresent(System.out::println);
+                });
+
+
+        System.out.println(optionalB2.orElse("noop"));
+
+        try {
+            optionalB2.orElseThrow(NullPointerException::new);
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+        }
+
+
+        //back to Streams
+        final String value = demoValues
+                .stream()
+                .filter(o -> o.contains("AAA"))
+                .findFirst().orElse("noop ");
+        System.out.println("value = " + value);
+
+        for(int i=0; i<10;i++){
+            final String valueParallel = demoValues
+                    .parallelStream()
+                    .filter(o -> o.contains("A"))
+                    .findFirst().orElse("noop ");
+            System.out.println("value ("+i+") = " + valueParallel);
+        }
+
+    }
+
+    public static Optional<String> addX(final String value) {
+        final Optional<String> optional = Optional.ofNullable(value);
+        final boolean present = optional.isPresent();
+        if(present){
+            return optional.map(v -> v + "_X");
+        } else{
+            return optional;
+        }
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_5.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_5 {
+
+    public static void main(String[] args) {
+        final List<String> demoValues = Arrays.asList("A", "B", "C", "D", "E");
+
+        System.out.println(demoValues.stream()
+                .reduce(String::concat)); //Optional[ABCDE]
+
+        System.out.println(demoValues.parallelStream()
+                .reduce(String::concat)); //Optional[ABCDE]
+
+        //result is ABCDE
+        System.out.println(demoValues.stream()
+                .reduce("", String::concat));
+
+        //result is ABCDE
+        System.out.println(demoValues.parallelStream()
+                .reduce("", String::concat));
+
+        //result is X_ABCDE
+        System.out.println(demoValues.stream()
+                .reduce("X_", String::concat));
+
+        //result is X_AX_BX_CX_DX_E
+        System.out.println(demoValues.parallelStream()
+                .reduce("X_", String::concat));
+
+        System.out.println(demoValues.stream()
+                .reduce("X_", (v1,v2)->{
+                    System.out.println("v1 -> " + v1);
+                    System.out.println("v2 -> " + v2);
+                    return v1.concat(v2)+"_";
+                }));
+
+        System.out.println(demoValues.parallelStream()
+                .reduce("X_", (v1,v2)->{
+//                    System.out.println("v1 -> " + v1);
+//                    System.out.println("v2 -> " + v2);
+                    final String result = v1.concat(v2) + "_";
+                    System.out.println("v1 " + v1 + " plus v2_ " + v2 + "_ => " + result);
+                    return result;
+                }));
+
+        final List<Integer> demoIntValues = Arrays.asList(1, 2, 3, 4, 5);
+
+        final Integer maxInteger = demoIntValues.parallelStream().reduce(Integer.MIN_VALUE, Integer::max);
+        System.out.println("maxInteger = " + maxInteger);
+
+
+//        final Integer maxInteger = demoIntValues.stream().reduce(Integer.MIN_VALUE, Integer::max);
+//        System.out.println("maxInteger = " + maxInteger);
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_6.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_6 {
+
+    public static void main(String[] args) {
+        final List<Integer> demoValues
+                = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+        //limit the input
+        System.out.println(demoValues
+                .stream().limit(4)
+                .collect(Collectors.toList()));
+
+        //limit the result
+        System.out.println(demoValues
+                .stream().filter((v) -> v > 4)
+                .limit(4)
+                .collect(Collectors.toList()));
+
+        System.out.println(demoValues
+                .stream().skip(4)
+                .collect(Collectors.toList()));
+
+        System.out.println(demoValues
+                .stream().sorted((v1, v2) -> Integer.compare(v2, v1))
+                .collect(Collectors.toList()));
+
+
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_7.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_7 {
+    public static void main(String[] args) {
+
+        // example result:
+        // [77, 79, 81, 95, 43, 10, 53, 48, 74, 68, 60, 86, 83, 24, 57, 28, 8,
+        //  85, 70, 66, 20, 14, 97, 73, 22, 36, 40, 39, 32, 19, 41, 67, 25, 88]
+        final Random random = new Random();
+        System.out.println(
+                Stream.generate(() -> random.nextInt(100))
+                        .limit(40)
+                        .distinct()
+                        .collect(Collectors.toList())
+        );
+
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_8.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_8 {
+    public static void main(String[] args) {
+        final List<Integer> demoValues
+                = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+        //find the maximum
+        System.out.println(demoValues
+                .stream().max(Integer::compareTo)
+        );
+        //find the BUG ;-)
+        System.out.println(demoValues
+                .stream().min((v1, v2) -> Integer.compare(v2, v1))
+        );
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/CHAP_1_2_9.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Created by Sven Ruppert on 22.11.13.
+ */
+public class CHAP_1_2_9 {
+
+    public static void main(String[] args) {
+        final List<Integer> demoValues
+                = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+
+
+        // true, some are matching
+        System.out.println("anyMatch " + demoValues.stream().map((e) -> {
+            System.out.println("e = " + e);
+            return e;
+        })
+                .anyMatch((v) -> v % 2 == 0));
+
+        //false, not all are matching
+        System.out.println("allMatch " + demoValues.stream().map((e) -> {
+            System.out.println("e = " + e);
+            return e;
+        })
+                .allMatch((v) -> v % 2 == 0));
+        //false, not all are NOT matching
+        System.out.println("noneMatch " + demoValues.stream() .map((e) -> {
+            System.out.println("e = " + e);
+            return e;
+        })
+                .noneMatch((v) -> v % 2 == 0));
+
+        //5 matching the filter, 2,4,6,8,10
+        System.out.println("count " + demoValues.stream().map((e) -> {
+            System.out.println("e = " + e);
+            return e;
+        })
+                .filter((v) -> v % 2 == 0)
+                .count());
+
+
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_2/DemoElement.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_2;
+
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * Created by Sven Ruppert on 15.11.13.
+ */
+public class DemoElement {
+
+    private String value;
+    private Date datum;
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("DemoElement{");
+        sb.append("value='").append(value).append('\'');
+        sb.append(", datum=").append(datum);
+        sb.append('}');
+        return sb.toString();
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public Date getDatum() {
+        return datum;
+    }
+
+    public void setDatum(Date datum) {
+        this.datum = datum;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(value, datum);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final DemoElement other = (DemoElement) obj;
+        return Objects.equals(this.value, other.value) && Objects.equals(this.datum, other.datum);
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/CHAP_1_3.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javafx.application.Application;
+import javafx.collections.ObservableList;
+import javafx.scene.Scene;
+import javafx.scene.chart.LineChart;
+import javafx.scene.chart.NumberAxis;
+import javafx.scene.chart.XYChart;
+import javafx.stage.Stage;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.TimeCounter;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.TimeCounterFormatter;
+
+/**
+ * Created by Sven Ruppert on 08.11.13.
+ */
+public class CHAP_1_3 extends Application {
+    public static final ExecutorService executorService = Executors.newCachedThreadPool();
+
+    private static final int WARMUP_COUNT = 1000;
+    private static final int CROP_COUNT = 10;
+    private static final boolean CROP_FIRST = true;
+
+    public static void main(String[] args) {
+        launch(args);
+    }
+
+    public static List<ChartValue> warmUp(final String prefix, final Worker worker) {
+        final List<ChartValue> result = new ArrayList<>();
+
+        for (int i = 0; i < WARMUP_COUNT; i++) {
+            System.out.print(prefix);
+
+            final long deltaT = ((TimeCounter) () -> {
+                final List<List<Integer>> demoValueMatrix = worker.generateDemoValueMatrix();
+                final List<List<Double>> interpolatedValues = worker.generateInterpolatedValues(demoValueMatrix);
+                System.out.print(" -> size() = " + interpolatedValues.size() + "  -> ");
+            }).execute();
+
+            new TimeCounterFormatter(deltaT).printAsNanoSec();
+
+            //add Value to Chart
+            if(CROP_FIRST){
+                if(CROP_COUNT >= i){
+                    //noop
+                } else{
+                    final ChartValue chartValue = new ChartValue(i, deltaT );
+                    result.add(chartValue);
+                }
+            } else{
+                    final ChartValue chartValue = new ChartValue(i, deltaT );
+                    result.add(chartValue);
+            }
+
+        }
+        return result;
+    }
+
+    @Override
+    public void start(Stage stage) throws Exception {
+        stage.setTitle("Time used for Worker");
+        final NumberAxis xAxis = new NumberAxis();
+        final NumberAxis yAxis = new NumberAxis();
+        xAxis.setLabel("Rounds");
+        final LineChart lineChart = new LineChart(xAxis, yAxis);
+
+        lineChart.setTitle("Time used for Worker");
+
+        final Scene scene = new Scene(lineChart, 800, 600);
+
+
+        final ObservableList<XYChart.Series> data = lineChart.getData();
+
+        data.add(createNextSeries("Serial", warmUp("Serial", new WorkerSerial())));
+        data.add(createNextSeries("Threads", warmUp("Threads", new WorkerParallelThreads())));
+        data.add(createNextSeries("ExecutorService", warmUp("ExecutorService", new WorkerParallelExecutorService(executorService))));
+        data.add(createNextSeries("Streams", warmUp("Streams", new WorkerParallelStreams())));
+        data.add(createNextSeries("WorkerJDK8", warmUp("WorkerJDK8", new WorkerJDK8(){})));
+
+        stage.setScene(scene);
+        stage.show();
+    }
+
+    private XYChart.Series createNextSeries(String prefix, List<ChartValue> serial) {
+        final XYChart.Series nextSeries = new XYChart.Series();
+        nextSeries.setName(prefix);
+        for (final ChartValue chartValue : serial) {
+            final XYChart.Data point = new XYChart.Data(chartValue.getX(), chartValue.getY());
+            nextSeries.getData().add(point);
+        }
+        return nextSeries;
+    }
+
+
+    public static class ChartValue {
+        public double x;
+        public double y;
+
+        public ChartValue(double x, double y) {
+            this.x = x;
+            this.y = y;
+        }
+
+        public double getX() {
+            return x;
+        }
+
+        public void setX(double x) {
+            this.x = x;
+        }
+
+        public double getY() {
+            return y;
+        }
+
+        public void setY(double y) {
+            this.y = y;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(x, y);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj == null || getClass() != obj.getClass()) {
+                return false;
+            }
+            final ChartValue other = (ChartValue) obj;
+            return Objects.equals(this.x, other.x) && Objects.equals(this.y, other.y);
+        }
+
+        @Override
+        public String toString() {
+            final StringBuilder sb = new StringBuilder("ChartValue{");
+            sb.append("x=").append(x);
+            sb.append(", y=").append(y);
+            sb.append('}');
+            return sb.toString();
+        }
+    }
+
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/Worker.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.List;
+
+/**
+ * Created by Sven Ruppert on 09.11.13.
+ */
+public interface Worker {
+
+    public static final int ANZAHL_KURVEN = 200;
+    public static final int ANZAHL_MESSWERTE = 10;
+    public static final int MAX_GENERATED_INT = 100;
+
+    public abstract List<List<Integer>> generateDemoValueMatrix();
+
+    public abstract List<List<Double>> generateInterpolatedValues(List<List<Integer>> baseValues);
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/WorkerJDK8.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.WorkLoadGenerator;
+
+/**
+ * Created by Sven Ruppert on 11.11.13.
+ */
+
+public interface WorkerJDK8 extends Worker {
+
+    @Override
+    public default List<List<Integer>> generateDemoValueMatrix(){
+        return Stream
+                .generate(this::generateDemoValuesForY)
+                .limit(ANZAHL_KURVEN)
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public default List<List<Double>> generateInterpolatedValues(List<List<Integer>> baseValues) {
+        final List<List<Double>> baseValueMatrix = generateDemoValueMatrix()
+                .parallelStream()
+                .map(v -> {
+                    final WorkLoadGenerator generator = new WorkLoadGenerator();
+                    return generator.generate(v);
+                })
+                .collect(Collectors.toList());
+        return baseValueMatrix;
+    }
+
+    public default List<Integer> generateDemoValuesForY(){
+        final Random random = new Random();
+        return Stream
+                .generate(() -> random.nextInt(MAX_GENERATED_INT))
+                .limit(ANZAHL_MESSWERTE)
+                .collect(Collectors.toList());
+    }
+
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/WorkerParallelExecutorService.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.DemoValueGenerator;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.WorkLoadGenerator;
+
+/**
+ * Created by Sven Ruppert on 11.11.13.
+ */
+public class WorkerParallelExecutorService implements Worker {
+
+    private final ExecutorService executorService;
+
+    public WorkerParallelExecutorService(ExecutorService executorService) {
+        this.executorService = executorService;
+    }
+
+
+    @Override
+    public List<List<Integer>> generateDemoValueMatrix() {
+        final List<Task> taskList = new ArrayList<>();
+        for(int i = 0; i< ANZAHL_KURVEN; i++){
+            taskList.add(new Task());
+        }
+
+        final List<List<Integer>> result = new ArrayList<>();
+        try {
+            final List<Future<List<Integer>>> futureList = executorService.invokeAll(taskList);
+            for (final Future<List<Integer>> future : futureList) {
+                final List<Integer> valueList = future.get();
+                result.add(valueList);
+            }
+
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    @Override
+    public List<List<Double>> generateInterpolatedValues(List<List<Integer>> baseValues) {
+        final List<TaskInterpolate> taskList = new ArrayList<>();
+        for (final List<Integer> baseValue : baseValues) {
+            final TaskInterpolate taskInterpolate = new TaskInterpolate();
+            taskInterpolate.values.addAll(baseValue);
+            taskList.add(taskInterpolate);
+        }
+
+        final List<List<Double>> result = new ArrayList<>();
+        try {
+            final List<Future<List<Double>>> futureList = executorService.invokeAll(taskList);
+            for (final Future<List<Double>> future : futureList) {
+                final List<Double> valueList = future.get();
+                result.add(valueList);
+            }
+
+        } catch (InterruptedException | ExecutionException e) {
+            e.printStackTrace();
+        }
+        return result;
+
+
+
+
+    }
+
+
+    public static class Task implements Callable<List<Integer>> {
+        private DemoValueGenerator valueGenerator = new DemoValueGenerator(){};
+
+        @Override
+        public List<Integer> call() {
+            final List<Integer> result = new ArrayList<>();
+            result.addAll(valueGenerator.generateDemoValuesForY());
+            return result;
+        }
+    }
+
+
+    public static class TaskInterpolate implements Callable<List<Double>>  {
+        public final List<Integer> values = new ArrayList<>();
+        public final List<Double> result = new ArrayList<>();
+
+        private final WorkLoadGenerator generator = new WorkLoadGenerator();
+
+        @Override
+        public List<Double> call() {
+            result.addAll(generator.generate(values));
+            return result;
+        }
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/WorkerParallelStreams.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.WorkLoadGenerator;
+
+/**
+ * Created by Sven Ruppert on 11.11.13.
+ */
+public class WorkerParallelStreams implements Worker{
+
+    @Override
+    public List<List<Integer>> generateDemoValueMatrix(){
+        return Stream
+                .generate(this::generateDemoValuesForY)
+                .limit(ANZAHL_KURVEN)
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public List<List<Double>> generateInterpolatedValues(List<List<Integer>> baseValues) {
+        final List<List<Double>> baseValueMatrix = generateDemoValueMatrix()
+                .parallelStream()
+                .map(v -> {
+                    final WorkLoadGenerator generator = new WorkLoadGenerator();
+                    return generator.generate(v);
+                })
+                .collect(Collectors.toList());
+        return baseValueMatrix;
+    }
+
+    public List<Integer> generateDemoValuesForY(){
+        final Random random = new Random();
+        return Stream
+                .generate(() -> random.nextInt(MAX_GENERATED_INT))
+                .limit(ANZAHL_MESSWERTE)
+                .collect(Collectors.toList());
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/WorkerParallelThreads.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.DemoValueGenerator;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.WorkLoadGenerator;
+
+/**
+ * Created by Sven Ruppert on 11.11.13.
+ */
+public class WorkerParallelThreads implements Worker {
+
+    @Override
+    public List<List<Integer>> generateDemoValueMatrix() {
+        final List<List<Integer>> result = new ArrayList<>();
+        final List<Task> taskList = new ArrayList<>();
+        for(int i = 0; i< ANZAHL_KURVEN; i++){
+            taskList.add(new Task());
+        }
+        for (final Task task : taskList) {
+            task.run();
+        }
+        for (final Task task : taskList) {
+            try {
+                task.join();
+                result.add(task.result);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public List<List<Double>> generateInterpolatedValues(List<List<Integer>> baseValues) {
+        final List<List<Double>> result = new ArrayList<>();
+        final List<TaskInterpolate> taskList = new ArrayList<>();
+        for (final List<Integer> baseValue : baseValues) {
+            final TaskInterpolate taskInterpolate = new TaskInterpolate();
+            taskInterpolate.values.addAll(baseValue);
+            taskList.add(taskInterpolate);
+        }
+        for (final TaskInterpolate task : taskList) {
+            task.run();
+        }
+        for (final TaskInterpolate task : taskList) {
+            try {
+                task.join();
+                result.add(task.result);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+
+    public static class Task extends Thread {
+        public List<Integer> result = new ArrayList<>();
+        private DemoValueGenerator valueGenerator = new DemoValueGenerator(){};
+
+        @Override
+        public void run() {
+            result.addAll(valueGenerator.generateDemoValuesForY());
+        }
+    }
+    public static class TaskInterpolate extends Thread {
+        public final List<Integer> values = new ArrayList<>();
+        public final List<Double> result = new ArrayList<>();
+
+        private final WorkLoadGenerator generator = new WorkLoadGenerator();
+
+        @Override
+        public void run() {
+            result.addAll(generator.generate(values));
+        }
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_3/WorkerSerial.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.DemoValueGenerator;
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools.WorkLoadGenerator;
+
+/**
+ * Created by Sven Ruppert on 11.11.13.
+ */
+public class WorkerSerial implements Worker {
+
+    @Override
+    public List<List<Double>> generateInterpolatedValues(List<List<Integer>> baseValues) {
+        final WorkLoadGenerator generator = new WorkLoadGenerator();
+        final List<List<Double>> result = new ArrayList<>();
+        for (final List<Integer> valueList : baseValues) {
+            final List<Double> doubleList = generator.generate(valueList);
+            result.add(doubleList);
+        }
+        return result;
+    }
+
+
+    private DemoValueGenerator valueGenerator = new DemoValueGenerator(){};
+
+    public List<List<Integer>> generateDemoValueMatrix() {
+        final List<List<Integer>> result = new ArrayList<>();
+        for (int i = 0; i < ANZAHL_KURVEN; i++) {
+            final List<Integer> demoValuesForY = valueGenerator.generateDemoValuesForY();
+            result.add(demoValuesForY);
+        }
+        return result;
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_4/ChartValue.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_4;
+
+import java.util.Objects;
+
+/**
+* Created by Sven Ruppert on 22.11.13.
+*/
+public class ChartValue {
+    public double x;
+    public double y;
+
+    public ChartValue(double x, double y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    public double getX() {
+        return x;
+    }
+
+    public void setX(double x) {
+        this.x = x;
+    }
+
+    public double getY() {
+        return y;
+    }
+
+    public void setY(double y) {
+        this.y = y;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(x, y);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final ChartValue other = (ChartValue) obj;
+        return Objects.equals(this.x, other.x) && Objects.equals(this.y, other.y);
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("ChartValue{");
+        sb.append("x=").append(x);
+        sb.append(", y=").append(y);
+        sb.append('}');
+        return sb.toString();
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_4/LineChartDemo.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_4;
+
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javafx.application.Application;
+import javafx.collections.ObservableList;
+import javafx.scene.Scene;
+import javafx.scene.chart.LineChart;
+import javafx.scene.chart.NumberAxis;
+import javafx.scene.chart.XYChart;
+import javafx.stage.Stage;
+import org.apache.commons.math3.analysis.UnivariateFunction;
+import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
+import org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator;
+
+/**
+ * Created by Sven Ruppert on 04.11.13.
+ */
+public class LineChartDemo extends Application {
+
+    private static final int STEP_SIZE = 100;
+    private static final int ANZAHL_KURVEN = 200;
+
+    @Override public void start(Stage stage) {
+        stage.setTitle("Line Chart Sample Extended");
+        final NumberAxis xAxis = new NumberAxis();
+        final NumberAxis yAxis = new NumberAxis();
+        xAxis.setLabel("Steps");
+        final LineChart lineChart = new LineChart(xAxis,yAxis);
+
+        lineChart.setTitle("Demovalues");
+
+        Scene scene  = new Scene(lineChart,800,600);
+
+        for(int i=0; i<10;i++){
+            final long start = System.nanoTime();
+            final List<XYChart.Series> serieses = generateNextSeries();
+            final long stop = System.nanoTime();
+            System.out.println("serieses.size() = " + serieses.size());
+            System.out.println("dt = " + NumberFormat.getIntegerInstance().format(stop - start));
+        }
+
+
+
+        final long start = System.nanoTime();
+        final List<XYChart.Series> serieses = generateNextSeries();
+        final long stop = System.nanoTime();
+
+        System.out.println("dt = " + NumberFormat.getIntegerInstance().format(stop - start));
+        final ObservableList<XYChart.Series> data = lineChart.getData();
+        data.addAll(serieses);
+
+        stage.setScene(scene);
+        stage.show();
+    }
+
+    public static void main(String[] args) {
+        launch(args);
+
+    }
+    private List<XYChart.Series> generateNextSeries(){
+        final List<XYChart.Series> chartSeries = getValuesForSeries()
+                .parallelStream()
+                .map(v -> {
+                    final XYChart.Series nextSeries = new XYChart.Series();
+                    int i = 0;
+                    for (final Double valueForY : v) {
+                        final XYChart.Data data = new XYChart.Data(i, valueForY);
+                        nextSeries.getData().add(data);
+                        i = i + 1;
+                    }
+                    return nextSeries;
+                }).collect(Collectors.toList());
+
+        return chartSeries;
+    }
+
+
+    private List<List<Double>> getValuesForSeries() {
+        final List<List<Integer>> demoValueMatrix = generateDemoValueMatrix();
+        final List<List<Double>> collect = demoValueMatrix
+                .parallelStream()
+                .map(v -> {
+                    final UnivariateFunction interpolateFunction = createInterpolateFunction(v);
+                    //baue Kurve auf
+                    final int anzahlValuesInterpolated = (v.size()-1) * STEP_SIZE;
+                    final List<Double> result = new ArrayList<>();
+                    for (int i = 0; i < anzahlValuesInterpolated-1; i++) {
+                        final double valueForY = interpolateFunction.value(i);
+                        result.add(valueForY);
+                    }
+                    return result;
+                })
+                .collect(Collectors.toList());
+        return collect;
+    }
+
+
+
+
+    private UnivariateFunction createInterpolateFunction(final List<Integer> values){
+        final double[] valueArrayX = new double[values.size()];
+        for (int i = 0; i < valueArrayX.length; i++) {
+            valueArrayX[i] = (double)i* STEP_SIZE;
+        }
+
+        final double[] valueArrayY = new double[values.size()];
+        int i=0;
+        for (final Integer value : values) {
+            valueArrayY[i] = (double) value.intValue();
+            i= i+1;
+        }
+
+        final UnivariateInterpolator interpolator = new SplineInterpolator();
+        final UnivariateFunction function = interpolator.interpolate(valueArrayX, valueArrayY);
+        return function;
+    }
+
+
+
+    public List<List<Integer>> generateDemoValueMatrix(){
+        return Stream
+                .generate(this::generateDemoValuesForY)
+                .limit(ANZAHL_KURVEN)              //Anzahl Kurven
+                .collect(Collectors.toList());
+    }
+
+    public List<Integer> generateDemoValuesForY(){
+        final Random random = new Random();
+        return Stream
+                .generate(() -> random.nextInt(100))
+                .limit(10)         //Messwerte in 10er Schritten
+                .collect(Collectors.toList());
+    }
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/chap_1_4/LineChartSerialDemo.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_4;
+
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Random;
+
+import javafx.application.Application;
+import javafx.collections.ObservableList;
+import javafx.scene.Scene;
+import javafx.scene.chart.LineChart;
+import javafx.scene.chart.NumberAxis;
+import javafx.scene.chart.XYChart;
+import javafx.stage.Stage;
+import org.apache.commons.math3.analysis.UnivariateFunction;
+import org.apache.commons.math3.analysis.interpolation.SplineInterpolator;
+import org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator;
+
+/**
+ * Created by Sven Ruppert on 06.11.13.
+ */
+public class LineChartSerialDemo extends Application {
+
+    private static final int STEP_SIZE = 100;
+    private static final int ANZAHL_KURVEN = 200;
+
+    @Override public void start(Stage stage) {
+        stage.setTitle("Line Chart Sample Extended");
+        final NumberAxis xAxis = new NumberAxis();
+        final NumberAxis yAxis = new NumberAxis();
+        xAxis.setLabel("Steps");
+        final LineChart lineChart = new LineChart(xAxis,yAxis);
+
+        lineChart.setTitle("Demovalues");
+
+        Scene scene  = new Scene(lineChart,800,600);
+
+        for(int i=0; i<10;i++){
+            final long start = System.nanoTime();
+            final List<XYChart.Series> serieses = generateNextSeries();
+            final long stop = System.nanoTime();
+            System.out.println("serieses.size() = " + serieses.size());
+            System.out.println("dt = " + NumberFormat.getIntegerInstance().format(stop - start));
+        }
+
+        final long start = System.nanoTime();
+        final List<XYChart.Series> serieses = generateNextSeries();
+        final long stop = System.nanoTime();
+
+        System.out.println("dt = " + NumberFormat.getIntegerInstance().format(stop - start));
+        final ObservableList<XYChart.Series> data = lineChart.getData();
+        data.addAll(serieses);
+
+        stage.setScene(scene);
+        stage.show();
+    }
+
+
+    public static void main(String[] args) {
+        launch(args);
+
+    }
+    private List<XYChart.Series> generateNextSeries(){
+        final List<XYChart.Series> result = new ArrayList<>();
+        final List<List<Double>> valuesForSeries = getValuesForSeries();
+        for (final List<Double> valuesForSery : valuesForSeries) {
+            final XYChart.Series nextSeries = new XYChart.Series();
+            int i = 0;
+            for (final Double valueForY : valuesForSery) {
+                final XYChart.Data data = new XYChart.Data(i, valueForY);
+                nextSeries.getData().add(data);
+                i = i + 1;
+            }
+            result.add(nextSeries);
+        }
+        return result;
+    }
+
+    private List<List<Double>> getValuesForSeries() {
+        final List<List<Double>> result = new ArrayList<>();
+        final List<List<Integer>> demoValueMatrix = generateDemoValueMatrix();
+        for (final List<Integer> v : demoValueMatrix) {
+            final UnivariateFunction interpolateFunction = createInterpolateFunction(v);
+            final int anzahlValuesInterpolated = (v.size()-1) * STEP_SIZE;
+            final List<Double> resultStep = new ArrayList<>();
+            for (int i = 0; i < anzahlValuesInterpolated-1; i++) {
+                final double valueForY = interpolateFunction.value(i);
+                resultStep.add(valueForY);
+            }
+            result.add(resultStep);
+        }
+        return result;
+    }
+
+
+
+
+
+
+    private UnivariateFunction createInterpolateFunction(final List<Integer> values){
+
+        final double[] valueArrayX = new double[values.size()];
+        for (int i = 0; i < valueArrayX.length; i++) {
+            valueArrayX[i] = (double)i* STEP_SIZE;
+        }
+
+        final double[] valueArrayY = new double[values.size()];
+        int i=0;
+        for (final Integer value : values) {
+            valueArrayY[i] = (double) value.intValue();
+            i= i+1;
+        }
+
+        final UnivariateInterpolator interpolator = new SplineInterpolator();
+        final UnivariateFunction function = interpolator.interpolate(valueArrayX, valueArrayY);
+        return function;
+    }
+
+
+    public List<List<Integer>> generateDemoValueMatrix(){
+        final List<List<Integer>> result = new ArrayList<>();
+        for (int i = 0; i< ANZAHL_KURVEN; i++){
+            final List<Integer> generatedDemoValuesForY = generateDemoValuesForY();
+            result.add(generatedDemoValuesForY);
+        }
+        return result;
+    }
+
+    public List<Integer> generateDemoValuesForY(){
+        final Random random = new Random();
+        final List<Integer> result = new ArrayList<>();
+        for(int i = 0; i<10;i++){
+            result.add(random.nextInt(100));
+        }
+        return result;
+    }
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/tools/DemoValueGenerator.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools;
+
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.chap_1_3.Worker;
+
+/**
+ * Created by Sven Ruppert on 12.11.13.
+ */
+public interface DemoValueGenerator {
+
+    public default List<Integer> generateDemoValuesForY() {
+        final Random random = new Random();
+        return Stream
+                .generate(() -> random.nextInt(Worker.MAX_GENERATED_INT))
+                .limit(Worker.ANZAHL_MESSWERTE)
+                .collect(Collectors.toList());
+
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/tools/Pair.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools;
+
+import java.util.Objects;
+
+/**
+* Created by Sven Ruppert on 15.11.13.
+*/
+public class Pair {
+
+    public int id;
+    public String value;
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id, value);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        final Pair other = (Pair) obj;
+        return Objects.equals(this.id, other.id) && Objects.equals(this.value, other.value);
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("Pair{");
+        sb.append("id=").append(id);
+        sb.append(", value='").append(value).append('\'');
+        sb.append('}');
+        return sb.toString();
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/tools/PairListGenerator.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools;
+
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.model.Pair;
+
+/**
+ * Created by Sven Ruppert on 15.11.13.
+ */
+
+public interface PairListGenerator {
+
+    public default List<Pair> generateDemoValues(){
+        final Random random = new Random();
+        return Stream
+                .generate(() -> {
+                    final Pair p = new Pair();
+                    p.id = random.nextInt(100);
+                    p.value = "Value + " + p.id;
+                    return p;
+                })
+                .limit(100)
+                .collect(Collectors.toList());
+    }
+
+}

src/main/java/org/rapidpm/demo/entwicklerpress/shortcut/java8_streams/tools/TimeCounter.java

+package org.rapidpm.demo.entwicklerpress.shortcut.java8_streams.tools;
+
+/**
+ * Created by Sven Ruppert on 11.11.13.
+ */
+public interface TimeCounter {
+
+    public abstract void doIt();
+
+    public default long execute(){
+        final long start = System.nanoTime();
+        doIt();
+        final long stop = System.nanoTime();
+        return (stop - start);
+    }
+
+}