Skip to content

Commit 64476a4

Browse files
committed
Started implementing grouping opperators.
1 parent ae7c436 commit 64476a4

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* GroupingOperators.java Feb 3 2014, 05:55
3+
*
4+
* Copyright 2014 Drunken Dev.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.drunkendev.lambdas;
20+
21+
import com.drunkendev.lambdas.domain.DomainService;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.Map.Entry;
25+
import java.util.stream.Collectors;
26+
27+
import static java.util.Arrays.stream;
28+
29+
30+
/**
31+
*
32+
* @author Brett Ryan
33+
*/
34+
public class GroupingOperators {
35+
36+
private final DomainService ds;
37+
38+
/**
39+
* Creates a new {@code GroupingOperators} instance.
40+
*/
41+
public GroupingOperators() {
42+
this.ds = new DomainService();
43+
}
44+
45+
public static void main(String[] args) {
46+
GroupingOperators go = new GroupingOperators();
47+
go.lambda40();
48+
go.lambda41();
49+
go.lambda42();
50+
go.lambda43();
51+
go.lambda44();
52+
go.lambda45();
53+
}
54+
55+
public void lambda40() {
56+
int[] numbers = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0};
57+
Map<Integer, List<Integer>> map = stream(numbers)
58+
.boxed()
59+
.collect(Collectors.groupingBy(n -> n % 5));
60+
for (Entry<Integer, List<Integer>> ent : map.entrySet()) {
61+
System.out.println(String.format(
62+
"Numbers with a remainder of %d when divided by 5:", ent.getKey()));
63+
ent.getValue().stream().forEach(System.out::println);
64+
}
65+
}
66+
67+
public void lambda41() {
68+
}
69+
70+
public void lambda42() {
71+
}
72+
73+
public void lambda43() {
74+
}
75+
76+
public void lambda44() {
77+
}
78+
79+
public void lambda45() {
80+
}
81+
82+
}

0 commit comments

Comments
 (0)