image

Index

Please note that index links point to page beginnings from the print edition. Locations are approximate in e-readers, and you may need to page down one or more times after clicking a link to get to the indexed material.

A

abstract classes, interfaces vs. 164–165

accumulator functions, 74, 76–77

as collector components, 90–94, 98–100

collection and, 90

in reduction over 10, 103

in reduction over references, 105–107

replaced in reference reduction, 108

rules for collectors, 101–102

rule for reduction, 107

anonymous inner classes

lambda expressions vs., 21–23

transforming into lambda expressions, 7

API evolution, default methods for. See default methods

archives, JarFile class, 117

Arrays class, stream-bearing methods, 114

arrays

spliterator performance and, 154–155

associativity constraint,

collectors, 102

reduction, 105

auto-boxing/unboxing, 48

stream performance and, 153–154

B

behaviors

associated with objects, 22

composing, 15–17

lambdas representing, 22

BitSet class, 118

bodies, lambda expression, scoping rules for 22–23

bottlenecks, concurrent collections and, 90

bound method references

overview of, 33

unbound method references vs., 33–35

boxing

auto-boxing/unboxing, 48

stream performance and, 153–154

BufferedReader class, 114–115

spliterator performance and, 154–155

C

capturing lambdas, 24

chaining pipelines, 84–88

characteristics method, Spliterator interface, 122

chars method, CharSequence class, 118

CharSequence class, 117–118

chip design, increasing core count, 3

class diagram conventions, 27

classes. See also by individual class name

abstract classes, 164–165

anonymous inner classes, 7, 21–23

codePoints() method, CharSequence

class, 118

collectingAndThen method,

Collectors class, 94–95

Collection interface

internal iteration and, 4

stream-bearing methods, 50, 112

Collection.forEach method, 4

collections

Collection interface, 4, 50, 112

concurrent. See concurrent collections

distributing processing of, 3

internal iteration of, 4

implementing fork/join, 13–14

processing, moving to streams, 9–12

collection, 67–70. See also collectors

concurrent, 90

examples, 75

reduction compared with, 74, 107–108

collectors. See also reduction operations

anatomy of, 88–90

examples, 93, 98–99

composing, 80–84

concurrent collection and, 90

combiner functions

creating as collector components, 98–100

finishers, 94–97

performance issues in choosing execution mode, 147–148

performance of, 155

reducing collectors, 108–109

rules for, 101–102

reduction over primitives, 103

reduction over references, 105–107

role in collection, 88

standalone Predefined collectors, 76–80

in rules for collectors, 101–102

writing collectors, 90–94, 97–100

command pattern, lambdas as

implementation of 5–6

Comparator interface

creating comparators for custom sort, 15

comparing method, Comparator interface, 16–17

as fine-grained API method, 16–18

overload resolution, 39–40

comparingDouble method, overload resolution, 40

comparingInt method, overload resolution, 40

comparingLong method, overload resolution, 40

compatibility

behavioral, 172

binary, 161

in type checking, 28, 36–37, 40

in collector definition, 102

problems with default methods, 170–172

source, 161, 170

composition

of behaviors, 15–17

of collectors, 80–84, 108–109

concat method, Stream interface, 114

concurrent collections

collector performance and, 155

collection to, 90

rules for collectors, 101

concurrent map merge, performance, 156–157

ConcurrentHashMap class, 158

confidence interval, in statistics, 143

constructor method references overloading with, 41–42

overview of, 35

syntax/lambda equivalent, 32

type checking, 35

Consumer interface, 29

contexts, for target typing, 30–31

conversion, reference to primitive streams, 56–57

correctness, mutation of local variables by lambdas and, 24–25

counting method, Collectors class, 82

D

DCE (dead code elimination), 141

debugging streams, 57–58

default methods

abstract classes and, 164–165

compatibility problems, 170–172

inheritance and, 166–170

overview of, 160–162

syntax, 165–166

using, 162–164

directories, Files class method and, 115–116

DISTINCT characteristic, Spliterator interface, 150

stateful operations and, 153

stream characteristics and, 150

distinct operation, 58–59, 150, 153

implementation, 152

divide-and-conquer algorithm, fork/join framework and, 119–120

DoubleStream interface

conversion from other stream types, 49

produced by Arrays.stream,114

Random class methods and, 119

reduction operations, 66

E

effective finality

evading restriction to, 25–26

restriction to, 24–25

encounter order, 58, 60, 70, 151–152

defined, 151

estimateSize method, Spliterator interface, 122

exceptions, 123–126

BufferedReader class throwing, 115

lambdas and, 37–38

wrapping in unchecked exceptions, 125–126

execution mode

execution context in choosing, 146–147

spliterator and collector performance in choosing, 147–148

workload in choosing, 147

expressions

lambda. See lambda expressions

regular. See regular expressions

external iteration, 2–3

F

field names, scoping rules for lambdas, 22

Files class

exception example, 123–125

stream-bearing methods, 115–116

filter method, Stream interface, 54, 153

final keyword, local variable capture and, 24–25

finishers, 94–97, 99

flatMap method, Stream interface, 56–57, 123–125, 128–130, 153

fluent style, 12

forEach method, Iterable interface, 4–7

forEach method, Stream interface, 47, 63,

side-effecting operations, 70–71,

forEachOrdered method, Stream interface

side-effecting operations, 70–71

forEachRemaining method, Iterator interface, 166

forEachRemaining method, Spliterator interface, 122

fork/join framework

divide-and-conquer algorithm and, 119–120

execution context and, 146

recursive decomposition and, 13–14

spliterators and, 120–122, 133

function types, 26

definition, 36

type checking lambdas against, 35–42

functional interfaces, 8

lambda expressions implementing, 26–30

use cases for, 29–30

functions, lambda expressions as, 20

G

garbage collection, 141–142

generate method, Stream interface, 112–113

get method, Optional class, 65

globbing, 127

Google Caliper, 142

Google Guava, 160

grep simulation example, 127–136

overview of, 127

groupingBy method, Collectors class, 79–84

performance, 156–157

I

icon at top right, class diagram

conventions, 27

identity constraint,

collectors, 101

reduction, 105

identity

anonymous inner classes vs. lambdas, 21

lambdas not possessing, 22

ifPresent method, Optional class, 65

immutability, classic tribute to, 131

inexact reference, 41

inheritance, default methods and, 166–170

instance method references

overview of, 33–35

syntax/lambda equivalent, 32

interfaces

interface basis of Java Collections Framework, 160

single abstract method, 7–8

intermediate operations, streams, 11, 45, 49, 51–60

internal iteration

change from external to, 2–3

implementing parallelism with, 12–14

using lambdas to make use of, 9–12

IntStream interface

produced by Arrays.stream, 114

conversion from other stream types, 49

Random class methods and, 119

reduction operations, 66

IOException

BufferedReader class throwing, 115

Files class, 115, 123–125

wrapping exceptions in unchecked exceptions, 125–126

isPresent method, Optional class, 65

iterate method, Stream interface

spliterator performance, 154–155

in stream creation, 112–113

iteration

external. See external iteration

from external to internal, 2–3

internal. See internal iteration

lambda expressions and, 7–9

streams compared with iterators, 45

Iterator.remove method, supplied by default method 163

J

JarFile class, 117

Java Collections Framework, 160

Java Microbenchmarking Harness. See JMH

JMH (Java Microbenchmarking Harness), 142–145

joining method, Collectors class, 77

uses finisher, 95–97

L

lambda expressions

anonymous inner classes vs., 21–23

contexts for, 30–31

composing behaviors, 15–17

and functional interfaces, 8, 26–30

and method and constructor references, 31–35

method calls as, 21

overload resolution, 35–42

overview of, 20

scoping rules for, 22–23

syntax of, 20–21

type checking, 35–38

variable capture, 23–26

lazy evaluation

search operations and, 64

streams and, 45–47

limit method, Stream interface, 59–60

high performance cost of parallelizing, 153

lines method

BufferedReader class, 114–115

Files class, 116

LineSpliterator, 132–135

local variable capture, lambda expressions, 24–25

LongStream

conversion from other stream types, 49

produced by Arrays.stream,114

Random class methods and, 119

reduction operations, 66

M

map method, Stream class, 54–56

map merge performance, 156–158

mapping method, Collectors class, 84

mapToDouble method, 55–56

mapToInt method, 55–56

mapToLong method, 55–56

matching, in type checking, 36–38

maxBy method, Collectors class, 82

memory mapping, Java NIO, 132

method references, 31–35

defined, 32

overloading with, 41–42

type checking, 35

methods

class diagram conventions and, 27

default methods. See default methods

static interface methods, 172–173

syntax, 165

microbenchmarking

caution regarding, 138

experimental method and, 143–146

JMH (Java Microbenchmarking Harness), 142

measuring dynamic runtime, 140–142

overview of, 140

minBy method, Collectors class, 82

mutable reduction. See also Collectors class, 67, 74, 89

mutation, of local variables, 25–26

N

naming scope

anonymous inner classes vs. lambdas, 21–22

rules for lambdas, 22–23

O

one-to-many mapping, of stream elements, 56–57

Optional class, 63–65

ORDERED characteristic, Spliterator interface, 150

ordering, performance and, 151–153

orElse method, Optional class, 65

orElseGet method, Optional class, 65

overload resolution

overloading with lambda expressions, 39–40

overloading with method references, 41–42

overview of, 38–39

P

parallelism

from collections to streams, 10–12

of collectors, 93

defined, 3

implementing with internal iteration, 4

non-interference in parallel operations, 60–62

workload and, 147

parallel-ready code, 25

parameter list, lambda syntax, 20

parameters

explicitly typed lambda, 20

scoping rules for lambdas, 22

parentheses, syntax for parameter list, 20

partitioningBy method, Collectors class, 79–80

pattern matching, 127

peek method, Stream interface, 57–58

peer review, in experimental method, 143

performance

boxing and unboxing and, 153–154

collectors and, 155

concurrent map merge, 156–157

example of performance analysis, 157–158

experimental method and, 143–146

factors in choosing execution mode, 146–148

JMH (Java Microbenchmarking Harness), 142

measuring dynamic runtime, 140–142

microbenchmarking and, 140

ordering and, 151–153

overview of, 138–140

parallelization of collectors and, 93

spliterators and, 154–155

stateful and stateless operations, 153

stream characteristics and, 148–150

pipelines

chaining, 84–88

debugging, 57–58

ending, 62–63

filtering stream elements, 54

mapping stream elements, 54–57

non-interference in parallel operations, 60–62

overview of, 49–50

reduction operations, 65–67

search operations, 63–65

side-effecting operations, 70–71

sorting and duplicating, 58–59

starting, 50–51

transforming, 51–52

truncating, 59–60

poly expressions, 35

Predicate interface, 29

prefix sums, 100, 131, 157

primitive specializations, of functional interfaces, 29

primitive streams, 48–49

conversion methods, 56–57

reduction operations, 102–104

processor speed, limitations to, 3

R

race conditions, mutation of local variables and, 25–26

Random class, 118

range method, IntStream interface, 113

rangeClosed method, IntStream interface, 113

recursive decomposition, 13–14

recursive lambda definitions, 23

reduce methods, Stream interface, 104

reducing methods, Collectors class, 108

reduction operations. See also collection

collection compared with, 74

composing collectors with reduction, 108–109

ending pipelines and, 62

mutable reduction, 67, 74

over primitive streams, 102–104

over reference streams, 104–108

overview of, 65–67

parallel mutable reduction, 89

regular expressions

java.util.regex.Pattern class method, 116–117

types of pattern matching, 127

return keyword, lambda syntax, 21

return types, matching function types, 37

runtime, measuring dynamic

DCE (dead code elimination), 141

garbage collection, 141

overview of, 140–141

warmup effects, 141

S

SAM interface. See functional interfaces

scope. See naming scope

search operations, Stream API, 63–64

advantages of lazy evaluation and, 46

ending pipelines and, 62

Optional class and, 65

side-effecting operations

ending pipelines and, 63

ordering in stream performance and, 152–153

Stream API, 70–71

SIZED characteristic, Spliterator interface, 150

skip method, Stream interface, 59–60

sorting (sorted operation)

sorting streams, 58–59

split method, Pattern class, 116–117

splitAsStream method, Pattern class, 116–117

Spliterator interface, 119–122

spliterators

creating streams from, 122–123

example applying, 132–136

methods, 121–122

overriding methods and, 162–163

overview of, 119–121

performance, 147–148, 154–155

SplittableRandom class, 118–119

stateful operations, stream performance, 153

stateless (non-capturing) lambdas, 24

stateless operations, stream performance, 153

statements, lambdas, 21

static method references

bound method references analogous to, 33

overview of, 32–33

syntax/lambda equivalent, 32

static methods

interfaces and, 161, 172–173

using static interface methods, 173

statistics, in experimental method, 143

Stream API

debugging, 57–58

ending pipelines, 62–63

examples of stream processing, 53

lazy evaluation and, 45–47

non-interference in parallel operations, 60–62

overview of, 44–45

parallel-ready code, 47–48

primitive streams, 48–49

search operations, 63–65

streams compared with iterators, 45

stream method, JarFile and ZipFile classes, 117

empty method, Stream interface, 50, 112

of method, Stream interface, 50, 112, 114

streams

chaining pipelines, 84–88

characteristics of, 148–150

collections of stream elements, 67–70

compared with iterators, 45

debugging, 57–58

definition of, 11

ending, 62–63

examples of stream processing, 53

filtering, 54

lazy evaluation and, 45–47

mapping, 54–56

non-interference in parallel operations, 60–62

one-to-many mapping, 56–57

ordering, 151–153

overview of, 44–45

performance. See performance

pipelines and, 49–50

primitive, 48–49

reduction operations, 65–67

search operations, 63–65

side-effecting operations, 70–71

sorting and deduplicating, 58–59

transforming pipelines, 51–52

truncating, 59–60

streams, creating

Arrays class methods, 114

BitSet class method, 118

BufferedReader class method, 114–115

CharSequence class method, 117–118

concat method, 114

Files class method, 115–116

iterate and generate methods, 112–113

JarFile class method, 117

Pattern class method, 116–117

Random class method, 118

range and rangeClosed methods, 113

spliterators and, 119–122

SplittableRandom class methods, 118–119

ZipFile class method, 117

summarizingDouble method, Collectors class, 83

summarizingInt method, Collectors class, 83

summarizingLong method, Collectors class, 83

summingDouble method, Collectors class, 83

summingInt method, Collectors class, 83

summingLong method, Collectors class, 83

Supplier interface, 29

anatomy of collectors and, 88–89

collector component, 74

creating collector components, 98–100

defined, 92–94

finishers, 95–96

rules for collectors, 101–102

standalone predefined collectors and, 78–79

syntax

default methods, 165–166

lambda, 20–21

method references, 32–35

T

target types, contexts providing, 30–31

this keyword, scoping rules and, 23

thread safety, 60–62

thrown types, matching function types, 37–38

throws clause, lambda expressions and, 21

toConcurrentMap method, Collectors class, 90, 156

toList method, Collectors class, 76–78, 89

toMap method, Collectors class, 76–78

toSet method, Collectors class, 76–78

truncating streams, 59–60

tryAdvance method, Spliterator interface, 121, 134

trySplit method, Spliterator interface, 121, 133–134

type checking

lambda expressions and, 35–38

overloading with lambda expressions, 40

type variables, 27

U

unbound method references, 33-35

unboxing

auto-boxing/unboxing, 48

stream performance and, 153–154

Unicode characters, 117–118

Unix pipeline, 44

unobtrusive parallelism, 13–14

use cases, for functional interfaces, 29–30

V

value sequences, streams as, 44–45

variables

capture, 23–26

declaration and assignment, 30

scoping rules for lambdas, 23–26

W

warmup effects, measuring dynamic runtime, 141

wildcards, in class diagrams, 27

workload, influence in choosing execution mode, 147

Z

ZipFile class, 117

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.203.96