View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.bean;
16  
17  import java.util.Map;
18  
19  import net.curre.prefcount.gui.type.Place;
20  import net.curre.prefcount.gui.type.WindowComponent;
21  
22  /**
23   * Object of this class represents a bean that holds all
24   * score and results for a preferance card game.
25   * <p/>
26   * Created date: Apr 9, 2007
27   *
28   * @author Yevgeny Nyden
29   */
30  public class GameResultBean {
31  
32    /** Indicates that all player data has been entered or not. */
33    private boolean finalScoresReady;
34  
35    /** Average mountain for this game. */
36    private Float averageMountain;
37  
38    /** Minimum mountain in this game. */
39    private Integer minMountain;
40  
41    /**
42     * Flag to indicate the Leningradka pref type.
43     * This value matters for the pool/mount ratio value.
44     * When this flag is true 1 pool = 2 mount points, when
45     * it is false 1 pool = 1 mount.
46     */
47    private boolean leningradka;
48  
49    /** Flag to indicate user preferences for mount divisibility. */
50    private boolean mountDivisibleByN;
51  
52    /** List with player statistics. */
53    private Map<Place, PlayerStatistics> playerStats;
54  
55    /** Player used for the divisible by N adjustments. */
56    private Place divisibleByNPlayer;
57  
58    /** Default ctor. */
59    public GameResultBean() {
60      this.leningradka = Settings.DEFAULT_PREF_TYPE.equals(WindowComponent.LENINGRAD.name());
61      this.mountDivisibleByN = Settings.DEFAULT_DIVISIBLE_BY.equals(WindowComponent.DIVISIBLE_BY_N.name());
62      this.divisibleByNPlayer = Settings.DEFAULT_ADJ_PLAYER;
63      this.minMountain = 0;
64    }
65  
66    /**
67     * Getter for the flag that indicates that the player
68     * final scores are ready for display.
69     *
70     * @return True if all the player final scores have been generated;
71     *         false otherwise.
72     */
73    public boolean isFinalScoresReady() {
74      return this.finalScoresReady;
75    }
76  
77    /**
78     * Sets the flag that indicates that the player
79     * final scores are ready for display to true.
80     */
81    public void setFinalScoresReady() {
82      this.finalScoresReady = true;
83    }
84  
85    /**
86     * Getter for the max pool value.
87     *
88     * @return The max pool.
89     */
90    public Integer getMaxPool() {
91      int maxPool = 0;
92      if (this.playerStats != null) {
93        for (PlayerStatistics stat : this.playerStats.values()) {
94          Integer pool = stat.getPool();
95          if (pool != null && pool > maxPool) {
96            maxPool = pool;
97          }
98        }
99      }
100     return maxPool;
101   }
102 
103   /**
104    * Getter for the player's average mountain.
105    *
106    * @return The player's average mountain.
107    */
108   public Float getAverageMountain() {
109     return this.averageMountain;
110   }
111 
112   /**
113    * Setter for the player's average mountain.
114    * This method will round the float number to the 2 digit after
115    * the decimal.
116    *
117    * @param averageMountain Player's average mountain to set.
118    */
119   public void setAverageMountain(Float averageMountain) {
120     if (averageMountain != null) {
121       averageMountain = Float.valueOf(Math.round(averageMountain * 100) / 100F);
122     }
123     this.averageMountain = averageMountain;
124   }
125 
126   /**
127    * Returns the minimum mountain in the game.
128    *
129    * @return the minimum mountain in the game.
130    */
131   public Integer getMinMountain() {
132     return this.minMountain;
133   }
134 
135   /**
136    * Setter for the minimum mountain in the game.
137    *
138    * @param minMountain Min mountain in the game to set.
139    */
140   public void setMinMountain(Integer minMountain) {
141     this.minMountain = minMountain;
142   }
143 
144   /**
145    * Getter for the Leningradka pref type flag.
146    * This value matters for the pool/mount ratio value.
147    * When this flag is true 1 pool = 2 mount points, when
148    * it is false 1 pool = 1 mount.
149    *
150    * @return true when the pref type is Leningradka; false otherwise.
151    */
152   public boolean isLeningradka() {
153     return this.leningradka;
154   }
155 
156   /**
157    * Setter for property 'leningradka'.
158    * This value matters for the pool/mount ratio value.
159    * When this flag is true 1 pool = 2 mount points, when
160    * it is false 1 pool = 1 mount.
161    *
162    * @param leningradka Value to set for property 'leningradka'.
163    */
164   public void setLeningradka(boolean leningradka) {
165     this.leningradka = leningradka;
166   }
167 
168   /**
169    * Getter for property 'mountNotDivisible'.
170    *
171    * @return true if mount divisibility does not matter;
172    *         false - assumes divisible by N (number of players).
173    */
174   public boolean isMountDivisibleByN() {
175     return this.mountDivisibleByN;
176   }
177 
178   /**
179    * Setter for the mount divisibility flag.
180    *
181    * @param mountDivisibleByN true if divisibility does not matter;
182    *                          false - divisible by N (players number).
183    */
184   public void setMountDivisibleByN(boolean mountDivisibleByN) {
185     this.mountDivisibleByN = mountDivisibleByN;
186   }
187 
188   /**
189    * Getter for the map of player statistics.
190    *
191    * @return Map of player statistics.
192    */
193   public Map<Place, PlayerStatistics> getPlayerStats() {
194     return this.playerStats;
195   }
196 
197   /**
198    * Setter for the player statistics map.
199    *
200    * @param playerStats Map of player statistics.
201    */
202   public void setPlayerStats(Map<Place, PlayerStatistics> playerStats) {
203     this.playerStats = playerStats;
204   }
205 
206   /**
207    * Setter for divisibleByNPlayer.
208    *
209    * @param divisibleByNPlayer Player used for the divisible by N adjustments.
210    */
211   public void setDivisibleByNPlayer(Place divisibleByNPlayer) {
212     this.divisibleByNPlayer = divisibleByNPlayer;
213   }
214 
215   /**
216    * Getter for property 'divisibleByNPlayer' -
217    * player used for the divisible by N adjustments.
218    *
219    * @return Value for property 'divisibleByNPlayer'.
220    */
221   public Place getDivisibleByNPlayer() {
222     return divisibleByNPlayer;
223   }
224 
225   /**
226    * Returns the number of players in the game.
227    *
228    * @return The number of players in the game.
229    */
230   public int getNumberOfPlayers() {
231     return this.playerStats.size();
232   }
233 
234   /** * Clears state associated with a game session. */
235   public void clearResults() {
236     divisibleByNPlayer = Settings.DEFAULT_ADJ_PLAYER;
237     this.finalScoresReady = false;
238 
239   }
240 
241   /** {@inheritDoc} */
242   @Override
243   public String toString() {
244     StringBuilder buff = new StringBuilder();
245     return buff.append(super.toString()).append(": finalScoresReady=").append(this.finalScoresReady).
246         append(", averageMountain=").append(this.averageMountain).
247         append(", minMountain=").append(this.minMountain).
248         append(", divisibleByNPlayer=").append(this.divisibleByNPlayer).append(';').toString();
249   }
250 
251 }