Skip to content

Commit a8cd586

Browse files
author
github-actions
committed
Google Java Format
1 parent cdf69b0 commit a8cd586

File tree

5 files changed

+59
-65
lines changed

5 files changed

+59
-65
lines changed

Exercise.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ public class Exercise {
22

33
public static void main(String[] args) {
44
Queries queries = new Queries(DataProvider.getFootballers());
5-
queries.getAllFootballersByBirthyear()
6-
.values().stream()
7-
.forEach(System.out::println);
5+
queries.getAllFootballersByBirthyear().values().stream().forEach(System.out::println);
86
// add more queries as you wish
97
}
108
}

FootballClub.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
2-
public record FootballClub(String name, int positionInAllTimeTable, int pointsInAllTimeTable) {
3-
4-
}
1+
public record FootballClub(String name, int positionInAllTimeTable, int pointsInAllTimeTable) {}

Footballer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import java.time.LocalDate;
22

3-
public record Footballer(String name, Position position, LocalDate birthDate, int sizeInCm, FootballClub footballClub,
4-
int numberOfGames, int numberOfGoals) {
5-
6-
}
3+
public record Footballer(
4+
String name,
5+
Position position,
6+
LocalDate birthDate,
7+
int sizeInCm,
8+
FootballClub footballClub,
9+
int numberOfGames,
10+
int numberOfGoals) {}

Position.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
public enum Position {
2-
GOALKEEPER,
3-
DEFENDER,
4-
MIDFIELDER,
5-
STRIKER;
2+
GOALKEEPER,
3+
DEFENDER,
4+
MIDFIELDER,
5+
STRIKER;
66
}

Queries.java

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,49 @@
1010

1111
public class Queries {
1212

13-
private ArrayList<Footballer> footballers;
14-
15-
public Queries(ArrayList<Footballer> footballers) {
16-
this.footballers = footballers;
17-
}
18-
19-
public int getTotalOfAllGoalsByMidfielders() {
20-
return footballers.stream()
21-
.filter(footballer -> footballer.position().equals(Position.MIDFIELDER))
22-
.mapToInt(footballer -> footballer.numberOfGoals())
23-
.sum();
24-
}
25-
26-
public Optional<Footballer> getNameOfVfLWolfsburgFootballerWithMostPlayedGames() {
27-
Predicate<Footballer> isFromWolfsburg = footballer -> footballer
28-
.footballClub().equals(new FootballClub("VfL Wolfsburg", 3, 1145));
29-
Comparator<Footballer> sortNumberOfGoalsAscending = (footballer1, footballer2) -> Integer
30-
.valueOf(footballer1.numberOfGames()).compareTo(footballer2.numberOfGames());
31-
32-
return footballers.stream()
33-
.filter(isFromWolfsburg)
34-
.max(sortNumberOfGoalsAscending);
35-
}
36-
37-
public List<FootballClub> getNameOfAllFootballClubs() {
38-
return footballers.stream()
39-
.map(footballer -> footballer.footballClub())
40-
.distinct()
41-
.toList();
42-
}
43-
44-
public boolean isFootballerWithSizeInCmLT170AndNumbreOfGoalsBT0() {
45-
return footballers.stream()
46-
.anyMatch(footballer -> footballer.sizeInCm() < 170 && footballer.numberOfGoals() > 0);
47-
}
48-
49-
public Map<Integer, List<Footballer>> getAllFootballersByBirthyear() {
50-
Function<Footballer, Integer> birthYear = footballer -> footballer.birthDate().getYear();
51-
return footballers.stream()
52-
.collect(Collectors.groupingBy(birthYear));
53-
}
54-
55-
public OptionalDouble getAverageNumberOfPointsFromAllBundesligaFootballClubs() {
56-
return footballers.stream()
57-
.map(footballer -> footballer.footballClub())
58-
.distinct()
59-
.filter(footballClub -> footballClub.positionInAllTimeTable() != -1)
60-
.mapToInt(footballClub -> footballClub.pointsInAllTimeTable())
61-
.average();
62-
}
13+
private ArrayList<Footballer> footballers;
14+
15+
public Queries(ArrayList<Footballer> footballers) {
16+
this.footballers = footballers;
17+
}
18+
19+
public int getTotalOfAllGoalsByMidfielders() {
20+
return footballers.stream()
21+
.filter(footballer -> footballer.position().equals(Position.MIDFIELDER))
22+
.mapToInt(footballer -> footballer.numberOfGoals())
23+
.sum();
24+
}
25+
26+
public Optional<Footballer> getNameOfVfLWolfsburgFootballerWithMostPlayedGames() {
27+
Predicate<Footballer> isFromWolfsburg =
28+
footballer -> footballer.footballClub().equals(new FootballClub("VfL Wolfsburg", 3, 1145));
29+
Comparator<Footballer> sortNumberOfGoalsAscending =
30+
(footballer1, footballer2) ->
31+
Integer.valueOf(footballer1.numberOfGames()).compareTo(footballer2.numberOfGames());
32+
33+
return footballers.stream().filter(isFromWolfsburg).max(sortNumberOfGoalsAscending);
34+
}
35+
36+
public List<FootballClub> getNameOfAllFootballClubs() {
37+
return footballers.stream().map(footballer -> footballer.footballClub()).distinct().toList();
38+
}
39+
40+
public boolean isFootballerWithSizeInCmLT170AndNumbreOfGoalsBT0() {
41+
return footballers.stream()
42+
.anyMatch(footballer -> footballer.sizeInCm() < 170 && footballer.numberOfGoals() > 0);
43+
}
44+
45+
public Map<Integer, List<Footballer>> getAllFootballersByBirthyear() {
46+
Function<Footballer, Integer> birthYear = footballer -> footballer.birthDate().getYear();
47+
return footballers.stream().collect(Collectors.groupingBy(birthYear));
48+
}
49+
50+
public OptionalDouble getAverageNumberOfPointsFromAllBundesligaFootballClubs() {
51+
return footballers.stream()
52+
.map(footballer -> footballer.footballClub())
53+
.distinct()
54+
.filter(footballClub -> footballClub.positionInAllTimeTable() != -1)
55+
.mapToInt(footballClub -> footballClub.pointsInAllTimeTable())
56+
.average();
57+
}
6358
}

0 commit comments

Comments
 (0)