View Javadoc
1 /* 2 * WeaponUsage.java 3 * 4 * Created on February 6, 2003, 2:12 AM 5 */ 6 7 package com.mlw.fps.model.business.vo; 8 9 import java.util.HashMap; 10 import java.util.Iterator; 11 12 /*** 13 * 14 * @author Matthew Wilson 15 */ 16 public class WeaponUsage 17 { 18 protected Weapon weapon; 19 protected Player player; 20 21 protected long shots; 22 protected long hits; 23 protected long kills; 24 protected long tks; 25 protected long damage; 26 protected long deaths; 27 28 protected java.util.Map locations; 29 protected java.util.Map percentages; 30 31 /*** Creates a new instance of WeaponUsage 32 */ 33 public WeaponUsage() 34 { 35 } 36 37 /*** Creates a new instance of WeaponUsage 38 */ 39 public WeaponUsage(Weapon weapon) 40 { 41 this.weapon= weapon; 42 } 43 44 public void add(WeaponUsage usage) 45 { 46 getLocations(); 47 shots += usage.shots; 48 hits += usage.hits; 49 damage += usage.damage; 50 51 for (Iterator iter= usage.getLocations().keySet().iterator(); iter.hasNext();) 52 { 53 String key= (String)iter.next(); 54 55 Long value= (Long)usage.getLocations().get(key); 56 Long total= (Long)locations.get(key); 57 if (total == null) 58 { 59 locations.put(key, value); 60 } 61 else 62 { 63 locations.put(key, new Long(value.longValue() + total.longValue())); 64 } 65 66 } 67 68 //kills += usage.kills; 69 //deaths += usage.deaths; 70 } 71 72 /*** Getter for property weapon. 73 * @return Value of property weapon. 74 */ 75 public Weapon getWeapon() 76 { 77 return this.weapon; 78 } 79 80 /*** Setter for property weapon. 81 * @param weapon New value of property weapon. 82 */ 83 public void setWeapon(Weapon weapon) 84 { 85 this.weapon= weapon; 86 } 87 88 /*** Getter for property player. 89 * @return Value of property player. 90 */ 91 public Player getPlayer() 92 { 93 return this.player; 94 } 95 96 /*** Setter for property player. 97 * @param player New value of property player. 98 */ 99 public void setPlayer(Player player) 100 { 101 this.player= player; 102 } 103 104 /*** Getter for property shots. 105 * @return Value of property shots. 106 */ 107 public Long getShots() 108 { 109 return new Long(this.shots); 110 } 111 112 /*** Setter for property shots. 113 * @param shots New value of property shots. 114 */ 115 public void setShots(Long shots) 116 { 117 this.shots= shots.longValue(); 118 } 119 120 /*** Setter for property shots. 121 * @param shots New value of property shots. 122 */ 123 public void addShots(long shots) 124 { 125 this.shots += shots; 126 } 127 128 /*** Getter for property hits. 129 * @return Value of property hits. 130 */ 131 public Long getHits() 132 { 133 return new Long(this.hits); 134 } 135 136 /*** Setter for property hits. 137 * @param hits New value of property hits. 138 */ 139 public void setHits(Long hits) 140 { 141 this.hits= hits.longValue(); 142 } 143 144 /*** Setter for property hits. 145 * @param hits New value of property hits. 146 */ 147 public void addHits(long hits) 148 { 149 this.hits += hits; 150 } 151 152 /*** Getter for property damage. 153 * @return Value of property damage. 154 */ 155 public Long getDamage() 156 { 157 return new Long(this.damage); 158 } 159 160 /*** Setter for property damage. 161 * @param damage New value of property damage. 162 */ 163 public void setDamage(Long damage) 164 { 165 this.damage= damage.longValue(); 166 } 167 168 /*** Setter for property damage. 169 * @param damage New value of property damage. 170 */ 171 public void addDamage(long damage) 172 { 173 this.damage += damage; 174 } 175 176 /*** 177 * @return 178 */ 179 public Long getDeaths() 180 { 181 return new Long(deaths); 182 } 183 public void addDeaths(long deaths) 184 { 185 this.deaths += deaths; 186 } 187 /*** 188 * @return 189 */ 190 public Long getKills() 191 { 192 return new Long(kills); 193 } 194 195 public void addKills(long kills) 196 { 197 this.kills += kills; 198 } 199 200 /*** 201 * @return 202 */ 203 public Long getTks() 204 { 205 return new Long(tks); 206 } 207 208 /*** 209 * @param long1 210 */ 211 public void setDeaths(Long long1) 212 { 213 deaths= long1.longValue(); 214 } 215 216 /*** 217 * @param long1 218 */ 219 public void setKills(Long long1) 220 { 221 kills= long1.longValue(); 222 } 223 224 /*** 225 * @param long1 226 */ 227 public void setTks(Long long1) 228 { 229 tks= long1.longValue(); 230 } 231 232 /*** 233 * @return 234 */ 235 public java.util.Map getLocations() 236 { 237 if (locations == null) 238 locations= new HashMap(6); 239 return locations; 240 } 241 242 /*** 243 * @param map 244 */ 245 public void setLocations(java.util.Map map) 246 { 247 locations= map; 248 } 249 250 /*** 251 * @return 252 */ 253 public java.util.Map getPercentages() 254 { 255 if (percentages == null) 256 { 257 percentages= new HashMap(getLocations().size()); 258 for (Iterator iter= locations.keySet().iterator(); iter.hasNext();) 259 { 260 String key= (String)iter.next(); 261 Long value= (Long)locations.get(key); 262 if (value.longValue()==0||hits==0) 263 { 264 percentages.put(key, new Double(0)); 265 } 266 else 267 { 268 percentages.put(key, new Double(100*((double)value.longValue() / (double)hits))); 269 } 270 } 271 } 272 return percentages; 273 } 274 275 }

This page was automatically generated by Maven