Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0f8c5f9

Browse filesBrowse files
committed
Implemented basic selection example.
1 parent 35e3d83 commit 0f8c5f9
Copy full SHA for 0f8c5f9

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Open diff view settings
Filter options
  • specification/src/main/java/com/iluwatar
Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Open diff view settings
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
package com.iluwatar;
22

3+
import java.util.Arrays;
4+
import java.util.List;
5+
import java.util.stream.Collectors;
6+
37
public class App {
48
public static void main( String[] args ) {
9+
// initialize creatures list
10+
List<Creature> creatures = Arrays.asList(new Goblin(), new Octopus(), new Dragon(), new Shark(), new Troll(), new KillerBee());
11+
// find all walking creatures
12+
System.out.println("Find all walking creatures");
13+
List<Creature> walkingCreatures = creatures.stream().filter(new MovementSelector(Movement.WALKING)).collect(Collectors.toList());
14+
walkingCreatures.stream().forEach(System.out::println);
15+
// find all dark creatures
16+
System.out.println("Find all dark creatures");
17+
List<Creature> darkCreatures = creatures.stream().filter(new ColorSelector(Color.DARK)).collect(Collectors.toList());
18+
darkCreatures.stream().forEach(System.out::println);
19+
// find all red and flying creatures
20+
System.out.println("Find all red and flying creatures");
21+
List<Creature> redAndFlyingCreatures = creatures.stream().filter(new ColorSelector(Color.RED).and(new MovementSelector(Movement.FLYING))).collect(Collectors.toList());
22+
redAndFlyingCreatures.stream().forEach(System.out::println);
523
}
624
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.