1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.curre.prefcount.service;
16
17 import java.util.List;
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20
21 import net.curre.prefcount.bean.GameResultBean;
22 import net.curre.prefcount.bean.PlayerStatistics;
23
24
25
26
27
28
29
30
31
32 public class ResultService {
33
34
35 private static Logger log = Logger.getLogger(ResultService.class.toString());
36
37
38
39
40
41
42
43
44 public static void generateFinalResults(GameResultBean rBean) {
45
46 if (log.isLoggable(Level.FINE)) {
47 log.fine("Generating final results for Bean: " + rBean);
48 }
49
50
51 int min = Integer.MAX_VALUE;
52 int sum = 0;
53 List<PlayerStatistics> playerStats = rBean.getPlayerStats();
54 for (PlayerStatistics stats : playerStats) {
55 int currMountain = stats.getNewMountain();
56 sum += currMountain;
57 if (currMountain < min) {
58 min = currMountain;
59 }
60 }
61 rBean.setAverageMountain((float) sum / (float) playerStats.size() - min);
62 rBean.setMinMountain(min);
63
64
65 for (int playerInd = 0; playerInd < playerStats.size(); ++playerInd) {
66 PlayerStatistics stats = playerStats.get(playerInd);
67 int totalSaldo = 0;
68 for (int otherInd = 0; otherInd < playerStats.size(); ++otherInd) {
69 if (playerInd != otherInd) {
70 Integer computedSaldo = stats.getVistSaldoMap().get(otherInd);
71 if (computedSaldo == null) {
72 PlayerStatistics statsOther = playerStats.get(otherInd);
73 final int currPlayerVists = stats.getVistsForPlayer(otherInd);
74 final int otherPlayerVists = statsOther.getVistsForPlayer(playerInd);
75 computedSaldo = currPlayerVists - otherPlayerVists;
76 stats.getVistSaldoMap().put(otherInd, computedSaldo);
77 statsOther.getVistSaldoMap().put(playerInd, -1 * computedSaldo);
78 }
79 totalSaldo += computedSaldo;
80 }
81 }
82
83 stats.getVistSaldoMap().put(playerInd, totalSaldo);
84 }
85 rBean.setFinalScoresReady(true);
86 }
87
88
89
90
91
92
93
94 public static void clearFinalResults(GameResultBean rBean) {
95
96 for (PlayerStatistics stats : rBean.getPlayerStats()) {
97 stats.getVistSaldoMap().clear();
98 }
99 rBean.setFinalScoresReady(false);
100 }
101
102
103
104 }