-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathResolver.java
More file actions
77 lines (67 loc) · 2.2 KB
/
Resolver.java
File metadata and controls
77 lines (67 loc) · 2.2 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ru.urfu.resolver;
import ru.urfu.model.*;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Resolver implements IResolver {
private final List<Player> players;
public Resolver(List<Player> players) {
this.players = players;
}
@Override
public int getCountWithoutAgency() {
return (int)players.stream()
.filter(p -> p.agency().isEmpty())
.count();
}
@Override
public int getMaxDefenderGoalsCount() {
return players.stream()
.filter(p -> p.position().equals(Position.DEFENDER))
.max(Comparator.comparing(p -> p.goals()))
.map(p -> p.goals())
.orElse(-1);
}
@Override
public String getTheExpensiveGermanPlayerPosition() {
return players.stream()
.filter(p -> p.nationality().equals("Germany"))
.max(Comparator.comparing(p -> p.cost()))
.map(p -> {
switch (p.position()) {
case (Position.GOALKEEPER):
return "Вратарь";
case (Position.DEFENDER):
return "Защитник";
case (Position.MIDFIELD):
return "Полузащитник";
default:
return "Нападающий";
}
})
.orElse("Ошибка: немецких игроков не найдено");
}
@Override
public String getTheRudestTeam() {
var teams = players
.stream()
.collect(Collectors.groupingBy(p -> p.team()));
var maxEntry = teams
.entrySet()
.stream()
.max(Comparator.comparing(entry ->
entry
.getValue()
.stream()
.mapToDouble(Player::rCards)
.average()
.orElse(0)
))
.orElse(null);
if (maxEntry == null) {
return "Ошибка: команд не найдено";
}
return maxEntry.getKey();
}
}