View Javadoc
1   /******************************************************************************
2    * WinLoss - Describe the Win Loss record against one player.
3    * $Id$
4    * 
5    * BuckoFIBS - Backgammon by BuckoSoft
6    * Copyright 2010 - Dick Balaska - BuckoSoft, Corp.
7    * 
8    * $Log$
9    * Revision 1.2  2010/12/30 17:38:19  dick
10   * Correct the cvs link.
11   *
12   * Revision 1.1  2010/12/24 02:58:03  dick
13   * Describe the Win Loss record against one player.
14   *
15   */
16  
17  /* 
18   * This program is free software: you can redistribute it and/or modify
19   * it under the terms of the GNU General Public License as published by
20   * the Free Software Foundation, either version 3 of the License, or
21   * (at your option) any later version.
22   *
23   * This program is distributed in the hope that it will be useful,
24   * but WITHOUT ANY WARRANTY; without even the implied warranty of
25   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26   * GNU General Public License for more details.
27   *
28   * You should have received a copy of the GNU General Public License
29   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30   *
31   * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>.
32   * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp.
33   * 
34   */
35  package com.buckosoft.fibs.domain;
36  
37  
38  /** A class to manage wins/losses for a Player.
39   * We need to be able to deal with them as numbers and present them as a string.
40   * @author dick
41   * @since 2010/12/23
42   * @version $Revision$ <br> $Date$
43   * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/main/java/com/buckosoft/fibs/domain/WinLoss.java">cvs WinLoss.java</a>
44   *
45   */
46  public class WinLoss  implements Comparable<WinLoss> {
47  	private int		wins;
48  	private int		losses;
49  
50  	/** Convienence constructor that takes the wins and losses
51  	 * @param wins The number of times you have beaten this opponent.
52  	 * @param losses The number of times you have lost to this opponent.
53  	 */
54  	public WinLoss(int wins, int losses) {
55  		this.wins = wins;
56  		this.losses = losses;
57  	}
58  
59  	public WinLoss() {
60  	}
61  
62  	/** Get the numeric value of this WinLoss
63  	 * @return wins/losses, more or less
64  	 */
65  	public double	getValue() {
66  		if (losses == 0)
67  			return(wins*10);
68  		if (wins == 0)
69  			return(-losses);
70  		return((double)wins/(double)losses);
71  	}
72  	
73  	/** Get the String value of this WinLoss
74  	 * @return "W-L"
75  	 */
76  	public String toString() {
77  		return("" + wins + "-" + losses);
78  	}
79  
80  	/** Compare the value of this WinLoss with that one.
81  	 * @param o The other player to compare
82  	 */
83  	@Override
84  	public int compareTo(WinLoss o) {
85  		if (this.getValue() < o.getValue())
86  			return(-1);
87  		if (this.getValue() > o.getValue())
88  			return(1);
89  		return(0);
90  	}
91  }
92