FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java8InAction/src/main/java/lambdasinaction/chap5/Finding.java at master · java8/Java8InAction · GitHub
java8
/
Java8InAction
Public
Notifications
You must be signed in to change notification settings
Fork
2.2k
Star
3.2k
Code
Issues
18
Pull requests
7
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Java8InAction
/
src
/
main
/
java
/
lambdasinaction
/
chap5
/
Finding.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (28 loc) · 1.04 KB
Breadcrumbs
Java8InAction
/
src
/
main
/
java
/
lambdasinaction
/
chap5
/
Finding.java
Copy path
File metadata and controls
39 lines (28 loc) · 1.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package
lambdasinaction
.
chap5
;
import
lambdasinaction
.
chap4
.*;
import
java
.
util
.
stream
.*;
import
java
.
util
.*;
import
static
lambdasinaction
.
chap4
.
Dish
.
menu
;
public
class
Finding
{
public
static
void
main
(
String
...
args
){
if
(
isVegetarianFriendlyMenu
()){
System
.
out
.
println
(
"Vegetarian friendly"
);
}
System
.
out
.
println
(
isHealthyMenu
());
System
.
out
.
println
(
isHealthyMenu2
());
Optional
<
Dish
>
dish
=
findVegetarianDish
();
dish
.
ifPresent
(
d
->
System
.
out
.
println
(
d
.
getName
()));
}
private
static
boolean
isVegetarianFriendlyMenu
(){
return
menu
.
stream
().
anyMatch
(
Dish
::
isVegetarian
);
}
private
static
boolean
isHealthyMenu
(){
return
menu
.
stream
().
allMatch
(
d
->
d
.
getCalories
() <
1000
);
}
private
static
boolean
isHealthyMenu2
(){
return
menu
.
stream
().
noneMatch
(
d
->
d
.
getCalories
() >=
1000
);
}
private
static
Optional
<
Dish
>
findVegetarianDish
(){
return
menu
.
stream
().
filter
(
Dish
::
isVegetarian
).
findAny
();
}
}
Back
|
FazBrowse Home
|
New Git URL