Skip to content

Commit e1ff9b6

Browse files
committed
typo fixes and indents
1 parent 72b6a86 commit e1ff9b6

File tree

9 files changed

+134
-156
lines changed

9 files changed

+134
-156
lines changed

src/main/java/lambdasinaction/chap1/FilteringApples.java

Lines changed: 78 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
public class FilteringApples{
77

8-
public static void main(String ... args){
8+
public static void main(String ... args){
99

10-
List<Apple> inventory = Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), new Apple(120, "red"));
10+
List<Apple> inventory = Arrays.asList(new Apple(80,"green"),
11+
new Apple(155, "green"),
12+
new Apple(120, "red"));
1113

1214
// [Apple{color='green', weight=80}, Apple{color='green', weight=155}]
1315
List<Apple> greenApples = filterApples(inventory, FilteringApples::isGreenApple);
@@ -29,81 +31,77 @@ public static void main(String ... args){
2931
List<Apple> weirdApples = filterApples(inventory, (Apple a) -> a.getWeight() < 80 ||
3032
"brown".equals(a.getColor()));
3133
System.out.println(weirdApples);
32-
33-
34-
35-
}
36-
37-
public static List<Apple> filterGreenApples(List<Apple> inventory){
38-
List<Apple> result = new ArrayList<>();
39-
for (Apple apple: inventory){
40-
if ("green".equals(apple.getColor())) {
41-
result.add(apple);
42-
}
43-
}
44-
return result;
45-
}
46-
47-
public static List<Apple> filterHeavyApples(List<Apple> inventory){
48-
List<Apple> result = new ArrayList<>();
49-
for (Apple apple: inventory){
50-
if (apple.getWeight() > 150) {
51-
result.add(apple);
52-
}
53-
}
54-
return result;
55-
}
56-
57-
public static boolean isGreenApple(Apple apple) {
58-
return "green".equals(apple.getColor());
59-
}
60-
public static boolean isHeavyApple(Apple apple) {
61-
return apple.getWeight() > 150;
62-
}
63-
64-
65-
66-
public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p){
67-
List<Apple> result = new ArrayList<>();
68-
for(Apple apple : inventory){
69-
if(p.test(apple)){
70-
result.add(apple);
71-
}
72-
}
73-
return result;
74-
}
75-
76-
public static class Apple {
77-
private int weight = 0;
78-
private String color = "";
79-
80-
public Apple(int weight, String color){
81-
this.weight = weight;
82-
this.color = color;
83-
}
84-
85-
public Integer getWeight() {
86-
return weight;
87-
}
88-
89-
public void setWeight(Integer weight) {
90-
this.weight = weight;
91-
}
92-
93-
public String getColor() {
94-
return color;
95-
}
96-
97-
public void setColor(String color) {
98-
this.color = color;
99-
}
100-
101-
public String toString() {
102-
return "Apple{" +
103-
"color='" + color + '\'' +
104-
", weight=" + weight +
105-
'}';
106-
}
107-
}
108-
109-
}
34+
}
35+
36+
public static List<Apple> filterGreenApples(List<Apple> inventory){
37+
List<Apple> result = new ArrayList<>();
38+
for (Apple apple: inventory){
39+
if ("green".equals(apple.getColor())) {
40+
result.add(apple);
41+
}
42+
}
43+
return result;
44+
}
45+
46+
public static List<Apple> filterHeavyApples(List<Apple> inventory){
47+
List<Apple> result = new ArrayList<>();
48+
for (Apple apple: inventory){
49+
if (apple.getWeight() > 150) {
50+
result.add(apple);
51+
}
52+
}
53+
return result;
54+
}
55+
56+
public static boolean isGreenApple(Apple apple) {
57+
return "green".equals(apple.getColor());
58+
}
59+
60+
public static boolean isHeavyApple(Apple apple) {
61+
return apple.getWeight() > 150;
62+
}
63+
64+
public static List<Apple> filterApples(List<Apple> inventory, Predicate<Apple> p){
65+
List<Apple> result = new ArrayList<>();
66+
for(Apple apple : inventory){
67+
if(p.test(apple)){
68+
result.add(apple);
69+
}
70+
}
71+
return result;
72+
}
73+
74+
public static class Apple {
75+
private int weight = 0;
76+
private String color = "";
77+
78+
public Apple(int weight, String color){
79+
this.weight = weight;
80+
this.color = color;
81+
}
82+
83+
public Integer getWeight() {
84+
return weight;
85+
}
86+
87+
public void setWeight(Integer weight) {
88+
this.weight = weight;
89+
}
90+
91+
public String getColor() {
92+
return color;
93+
}
94+
95+
public void setColor(String color) {
96+
this.color = color;
97+
}
98+
99+
public String toString() {
100+
return "Apple{" +
101+
"color='" + color + '\'' +
102+
", weight=" + weight +
103+
'}';
104+
}
105+
}
106+
107+
}

src/main/java/lambdasinaction/chap3/Sorting.java

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@
55

66
public class Sorting {
77

8-
public static void main(String...args){
8+
public static void main(String...args){
99

1010
// 1
11-
List<Apple> inventory = new ArrayList<>();
12-
inventory.addAll(Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), new Apple(120, "red")));
11+
List<Apple> inventory = new ArrayList<>();
12+
inventory.addAll(Arrays.asList(new Apple(80,"green"), new Apple(155, "green"), new Apple(120, "red")));
1313

14-
// [Apple{color='green', weight=80}, Apple{color='red', weight=120}, Apple{color='green', weight=155}]
15-
inventory.sort(new AppleComparator());
16-
System.out.println(inventory);
14+
// [Apple{color='green', weight=80}, Apple{color='red', weight=120}, Apple{color='green', weight=155}]
15+
inventory.sort(new AppleComparator());
16+
System.out.println(inventory);
1717

1818
// reshuffling things a little
1919
inventory.set(1, new Apple(30, "green"));
2020

2121
// 2
2222
// [Apple{color='green', weight=30}, Apple{color='green', weight=80}, Apple{color='green', weight=155}]
2323
inventory.sort(new Comparator<Apple>() {
24-
public int compare(Apple a1, Apple a2){
25-
return a1.getWeight().compareTo(a2.getWeight());
26-
}
27-
});
28-
System.out.println(inventory);
24+
public int compare(Apple a1, Apple a2){
25+
return a1.getWeight().compareTo(a2.getWeight());
26+
}});
27+
System.out.println(inventory);
2928

3029
// reshuffling things a little
3130
inventory.set(1, new Apple(20, "red"));
@@ -42,44 +41,44 @@ public int compare(Apple a1, Apple a2){
4241
// [Apple{color='red', weight=10}, Apple{color='red', weight=20}, Apple{color='green', weight=155}]
4342
inventory.sort(comparing(Apple::getWeight));
4443
System.out.println(inventory);
45-
}
44+
}
4645

47-
public static class Apple {
48-
private Integer weight = 0;
49-
private String color = "";
46+
public static class Apple {
47+
private Integer weight = 0;
48+
private String color = "";
5049

51-
public Apple(Integer weight, String color){
52-
this.weight = weight;
53-
this.color = color;
54-
}
50+
public Apple(Integer weight, String color){
51+
this.weight = weight;
52+
this.color = color;
53+
}
5554

56-
public Integer getWeight() {
57-
return weight;
58-
}
55+
public Integer getWeight() {
56+
return weight;
57+
}
5958

60-
public void setWeight(Integer weight) {
61-
this.weight = weight;
62-
}
59+
public void setWeight(Integer weight) {
60+
this.weight = weight;
61+
}
6362

64-
public String getColor() {
65-
return color;
66-
}
63+
public String getColor() {
64+
return color;
65+
}
6766

68-
public void setColor(String color) {
69-
this.color = color;
70-
}
67+
public void setColor(String color) {
68+
this.color = color;
69+
}
7170

72-
public String toString() {
73-
return "Apple{" +
74-
"color='" + color + '\'' +
75-
", weight=" + weight +
76-
'}';
77-
}
78-
}
71+
public String toString() {
72+
return "Apple{" +
73+
"color='" + color + '\'' +
74+
", weight=" + weight +
75+
'}';
76+
}
77+
}
7978

80-
static class AppleComparator implements Comparator<Apple> {
81-
public int compare(Apple a1, Apple a2){
82-
return a1.getWeight().compareTo(a2.getWeight());
83-
}
84-
}
85-
}
79+
static class AppleComparator implements Comparator<Apple> {
80+
public int compare(Apple a1, Apple a2){
81+
return a1.getWeight().compareTo(a2.getWeight());
82+
}
83+
}
84+
}

src/main/java/lambdasinaction/chap4/Filtering.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,5 @@ public static void main(String...args){
1515
.forEach(System.out::println);
1616

1717
numbers.stream().limit(20).forEach(System.out::println);
18-
1918
}
20-
21-
22-
23-
}
19+
}

src/main/java/lambdasinaction/chap4/Finding.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
public class Finding{
88

99
public static void main(String...args){
10-
1110
if(isVegetarianFriendlyMenu()){
1211
System.out.println("Vegetarian friendly");
1312
}
@@ -17,7 +16,6 @@ public static void main(String...args){
1716

1817
Optional<Dish> dish = findVegetarianDish();
1918
dish.ifPresent(d -> System.out.println(d.getName()));
20-
2119
}
2220

2321
private static boolean isVegetarianFriendlyMenu(){
@@ -36,4 +34,4 @@ private static Optional<Dish> findVegetarianDish(){
3634
return menu.stream().filter(Dish::isVegetarian).findAny();
3735
}
3836

39-
}
37+
}

src/main/java/lambdasinaction/chap4/Mapping.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static void main(String...args){
1313
.map(Dish::getName)
1414
.collect(toList());
1515
System.out.println(dishNames);
16-
1716

1817
// map
1918
List<String> words = Arrays.asList("Hello", "World");
@@ -38,7 +37,6 @@ public static void main(String...args){
3837
)
3938
.filter(pair -> (pair[0] + pair[1]) % 3 == 0)
4039
.collect(toList());
41-
pairs.forEach(e -> System.out.println("(" + e[0] + ", " + e[1] + ")"));
42-
40+
pairs.forEach(pair -> System.out.println("(" + pair[0] + ", " + pair[1] + ")"));
4341
}
44-
}
42+
}

src/main/java/lambdasinaction/chap4/PuttingIntoPractice.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
public class PuttingIntoPractice{
99
public static void main(String ...args){
10-
Trader raoul = new Trader("Raoul", "Cambridge");
11-
Trader mario = new Trader("Mario","Milan");
12-
Trader alan = new Trader("Alan","Cambridge");
13-
Trader brian = new Trader("Brian","Cambridge");
10+
Trader raoul = new Trader("Raoul", "Cambridge");
11+
Trader mario = new Trader("Mario","Milan");
12+
Trader alan = new Trader("Alan","Cambridge");
13+
Trader brian = new Trader("Brian","Cambridge");
1414

1515
List<Transaction> transactions = Arrays.asList(
16-
new Transaction(brian, 2011, 300),
17-
new Transaction(raoul, 2012, 1000),
16+
new Transaction(brian, 2011, 300),
17+
new Transaction(raoul, 2012, 1000),
1818
new Transaction(raoul, 2011, 400),
1919
new Transaction(mario, 2012, 710),
2020
new Transaction(mario, 2012, 700),

src/main/java/lambdasinaction/chap4/Reducing.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ public static void main(String...args){
1717

1818
int max = numbers.stream().reduce(0, (a, b) -> Integer.max(a, b));
1919
System.out.println(max);
20-
2120
}
22-
23-
24-
}
21+
}

src/main/java/lambdasinaction/chap4/StreamBasic.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ public static void main(String...args){
1414
.filter(d -> d.getCalories() > 300)
1515
.map(Dish::getName)
1616
.limit(3)
17-
.collect(toList());
18-
17+
.collect(toList());
1918
System.out.println(names);
20-
21-
2219
}
23-
24-
2520
}

0 commit comments

Comments
 (0)