Streams, Collectors, and Optionals for Data Processing in Java 8
This course shows advanced patterns to process data in Java 8 using lambdas, streams, spliterators, optionals, and collectors. It shows how to build your own spliterators to connect streams to non-standard data sources, and to build your own collectors.
What you'll learn
The Stream API and the Collectors are two new additions to the JDK in Java 8 that allow the efficient processing of data using the map / filter / reduce approach. It brings many new patterns on the table, and ways to extend them. We show how to connect streams to non-standard sources of data, how to build streams on other streams. The notion of Optional, introduced to handle the reduction of empty streams is also shown on advanced data processing patterns. And at last, collectors are shown, basic patterns first then advanced ones, where we build our own custom collector.
Table of contents
- Introduction to the Course 2m
- What Are You Going to Learn in This Course? 3m
- What Should You Know to Follow This Course? Agenda of This Module 2m
- What Is a Spliterator? 4m
- The Spliterator Interface, What Do We Need to Implement? 3m
- The ArrayListSpliterator: the tryAdvance() Method 2m
- The ArrayListSpliterator: the trySplit() Method 3m
- Introduction to the Live Coding: How to Write a Spliterator 2m
- Using Our Own Spliterator: Setting up the Application 2m
- Using Our Own Spliterator: Writing the Use Case Pattern 2m
- Implementing Our Own Spliterator: The First Methods 3m
- Implementing Our Own Spliterator: The tryAdvance() Method 4m
- Implementing the tryAdvance() Method: Setting the Returned Object 2m
- Implementing Our Own Spliterator: Running the Example 1m
- Live Coding Session Wrap-up 1m
- Module Wrap-up 2m
- Version Check 0m
- Introduction and Agenda of the module 2m
- Concatenating Streams: The Stream.concat Pattern 3m
- Merging Streams: The Stream.of and flatMap Pattern 3m
- How Does the flatMap Pattern Work: Examples 2m
- Splitting a Text into Words Using the flatMap Pattern 3m
- Splitting a Text into Words: Putting the Result in a Set 2m
- State of a Stream: The Stream.characteristics() Method 3m
- What Are the Eight Characteristics of a Stream? 2m
- How Does the Steam Methods Modify the State of a Stream 3m
- State of a Stream: A First Example 2m
- How to Use the Stream.sorted() Method with a Comparator 1m
- Live Coding Session: Presentation of the Example 2m
- Live Coding: Merging Streams Using Stream.of and flatMap 3m
- Live Coding: Splitting a Large Text in Words Using flatMap 4m
- Live Coding Session Summary 1m
- Streams of Numbers: Converting from a Stream of Objects 2m
- Optimizing the Conversion from a Stream of Objects 1m
- Patterns to Build Streams of Numbers 2m
- Specialized Methods: min(), max() and summaryStatistics() 3m
- Live Coding Session: Introduction of the Scrabble Example 2m
- Live Coding: Computing the Score of a Word in Scrabble 3m
- Live Coding: Getting the Word with the Best Score 3m
- Live Coding: Computing Statistics on the Words of Shakespeare 2m
- Live Coding Session and Module Wrap-up 3m
- Introduction and Agenda of the Module 2m
- Building Parallel Processing on Multithread 3m
- Tools for Parallel Processing in the JDK 3m
- Parallel Streams: First Patterns 2m
- Caveats in Parallel Processing: Synchronization and Visibility 2m
- Stateful and Stateless Operations: The Limit Method Example 3m
- How to Tell a Stateless Operation from a Stateful One 1m
- Parallel Performance Analysis: Description of the Use Case 3m
- Parallel Performance Analysis: Understanding the Computing Times 2m
- A Sneaky Stateful Operation: The unordered() Method 2m
- Parallel Reduction: What Not to Do! 4m
- Tuning Parallelism: Setting the Size of the Common Fork Join Pool 2m
- Tuning Parallelism: Setting the Executor of a Computation 2m
- Live Coding: Understanding the Multithreaded Computation 4m
- Live Coding: Parallel Reduction, How Can It Go Wrong? 3m
- Live Coding: Parallel Reduction, Hint at the Collector Pattern 1m
- Live Coding Session Summary 1m
- Module Wrap-up 3m
- Introduction and Agenda of the Module 2m
- Optional: A First Explanation of the Concept 3m
- Patterns to Use an Optional as a Wrapper Type That Can Be Empty 2m
- Patterns to Build an Optional from Scratch 3m
- More Optional Patterns: The Map, Filter and ifPresent Patterns 3m
- How We Can See an Optional as a Special Kind of Stream 1m
- Introduction to Advanced Optional Patterns: The NewMath Example 2m
- Building a First Data Processing Pipeline with the NewMath Class 2m
- How Does the Optional.flatMap Pattern Work? 2m
- Leveraging the flatMap Pattern to Convert an Optional to a Stream 4m
- Building a Parallel Data Processing Pipeline with NewMath 1m
- Introduction to the Live Coding Session 0m
- Live Coding: How Not to Process Doubles with NewMath 3m
- Live Coding: Failing to Go Parallel with the Wrong Pattern 3m
- Live Coding: Building an Optional flatMapper for NewMath 3m
- Live Coding: Analyzing the Optional flatMapper 1m
- Live Coding: Parallel Stream with the Optional flatMapper 3m
- Live Coding Session Summary 2m
- Module Wrap-up 2m
- Introduction and Agenda of the Module 2m
- What Is a Collector? A Look Back at the Reduction Step 1m
- A First Anti-pattern to Reduce a Stream in a List 2m
- Reduction in a List: The Right Pattern with a Collector 1m
- The Collectors Class: We Have a Collector for That 3m
- Computing a Max and an Average with a Collector 2m
- Building Strings with a Collector 1m
- Collecting Data in a Set 1m
- Collecting in a Map: The partiionningBy and groupingBy Patterns 2m
- Adding a Downstream Collector to Process Map Values 2m
- Specifying Built Containers, the collectingAndThen Pattern 3m
- Live Coding: Introducing the Shakespeare Plays Scrabble Use Case 3m
- Live Coding: Building Histograms to Extract the Best Words 5m
- Live Coding: Writing Whizzing with a Blank Letter 2m
- Live Coding: Computing the Histogram of the Letters of a Word 3m
- Live Coding: Computing the Number of Blanks Need for Whizzing 4m
- Live Coding: Computing the Score of Words with Blank Letters 3m
- Live Coding: Computing the Best Words with Blanks 2m
- Live Coding Session Summary 2m
- Module Wrap-up 3m
- Introduction and Agenda of the Module 2m
- What if We Need Collectors that Are Not in the Collectors Class? 1m
- Collectors Made of a Supplier, an Accumulator, and a Combiner 2m
- Example of a Supplier and Accumulator for an ArrayList 2m
- Example of a Combiner for an ArrayList 2m
- Putting it All Together: The Collector.of Pattern 2m
- Live Coding: Presenting the Actors and Movies Use Case 3m
- Live Coding: Counting the Number of Actors 3m
- Live Coding: Finding the Actor That Played in the Most Movies 4m
- Live Coding: Adding the Year Constraint, Introduction 2m
- Live Coding: Setting the Custom Downstream Collector 1m
- Live Coding: Writing the Supplier for the Custom Collector 2m
- Live Coding: Writing the Accumulator 3m
- Live Coding: Writing the Combiner by Merging Maps 3m
- Live Coding: Taking a Global Look at the Custom Collector 2m
- Live Coding: Extracting the Max of the Submap 4m
- Live Coding: Extracting the Max of the Main Map 2m
- Live Coding Session Summary 2m
- Other Custom Collectors: The summaryStatistics Pattern 2m
- Module Wrap-up 2m