View Javadoc
1 /* 2 * WeaponStats.java 3 * 4 * Created on February 6, 2003, 2:21 AM 5 */ 6 7 package com.mlw.fps.model.business.dao.memmory; 8 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.Date; 12 import java.util.Iterator; 13 import java.util.List; 14 import java.util.Map; 15 import java.util.TreeMap; 16 17 import com.mlw.fps.model.business.vo.Game; 18 import com.mlw.fps.model.business.vo.Kill; 19 import com.mlw.fps.model.business.vo.KillPlayer; 20 import com.mlw.fps.model.business.vo.Round; 21 22 /*** This class holds the data that is being parsed. There is also a dao 23 * implementation that acces this singleton in the package: 24 * <code>com.mlw.fps.mode.dao.file.</code> 25 * 26 * @author Matthew Wilson 27 */ 28 public class StaticData 29 { 30 private static StaticData instance = null; 31 32 private boolean initialized = false; 33 34 private List kills = new ArrayList(); 35 private Map games = new TreeMap(); 36 37 private Map rounds = new TreeMap(); 38 39 private Map maps = new TreeMap(); 40 private Map mapsByName = new TreeMap(); 41 42 private Map players = new TreeMap(); 43 private Map playersByName = new TreeMap(); 44 45 private Map weapons = new TreeMap(); 46 private Map weaponsByName = new TreeMap(); 47 48 private long sequence = 0; 49 50 /*** Initializes this class. 51 * @param logDir Directory containing the logs. 52 */ 53 public void init(String logDir) 54 { 55 if( !instance.initialized() ) 56 { 57 try 58 { 59 instance = new StaticData(); 60 com.mlw.fps.load.Loader loader = new com.mlw.fps.load.adapter.HalfLifeLoader(logDir); 61 loader.load(); 62 instance.initialized = true; 63 64 /*TODO: clean up empty games, this is a bug in the loader... 65 for( Iterator games = new ArrayList(this.games.values()).iterator(); games.hasNext();) 66 { 67 Game game = (Game)games.next(); 68 if( game.getRounds().size()==0) 69 { 70 System.out.println("REMOVE: " + game); 71 this.games.remove(game.getPk()); 72 } 73 }*/ 74 } 75 catch(Exception e) 76 { 77 e.printStackTrace(); 78 } 79 } 80 } 81 82 /*** Gets is this class initialized. 83 * @return a boolean, is the Static data 84 * initialized? 85 */ 86 public boolean initialized() 87 { 88 return initialized; 89 } 90 91 /*** Retrievs the maps. 92 * @return A Map of the maps. 93 */ 94 public Map getMaps() 95 { 96 return maps; 97 } 98 public Map getMapsByName() 99 { 100 return mapsByName; 101 } 102 103 /*** Retrievs the kills. 104 * @return A Map of the kills. 105 */ 106 public List getKills() 107 { 108 return kills; 109 } 110 111 /*** Retrievs the rounds. 112 * @return A Map of the rounds. 113 */ 114 public Map getRounds() 115 { 116 return rounds; 117 } 118 119 /*** Retrievs the players. 120 * @return A Map of the playes. 121 */ 122 public Map getPlayers() 123 { 124 return players; 125 } 126 127 /*** Retrievs the playuers 128 * @return A Map of the players. 129 */ 130 public Map getPlayersByName() 131 { 132 return playersByName; 133 } 134 135 /*** Retrievs the weapons. 136 * @return A Map of the weapons. 137 */ 138 public Map getWeapons() 139 { 140 return weapons; 141 } 142 143 /*** Retrievs the weapons. 144 * @return A Map of the weapons. 145 */ 146 public Map getWeaponsByName() 147 { 148 return weaponsByName; 149 } 150 151 public synchronized String next() 152 { 153 return String.valueOf(sequence++); 154 } 155 156 /*** Implementation of the Static pattern. This is the method to retieve an 157 * iunstance of this class. 158 * @return Implementation of the Static pattern 159 */ 160 public static StaticData instance() 161 { 162 if( instance == null ) 163 { 164 instance = new StaticData(); 165 } 166 return instance; 167 } 168 169 /*** Getter for property games. 170 * @return Value of property games. 171 */ 172 public Map getGames() 173 { 174 return this.games; 175 } 176 177 public List getGames(Map filters) 178 { 179 if( filters==null || filters.isEmpty() ) return new ArrayList(games.values()); 180 181 Date date = null; 182 Collection collection = null; 183 184 List list = new ArrayList(); 185 186 for( Iterator games = this.games.values().iterator(); games.hasNext();) 187 { 188 Game game = (Game)games.next(); 189 190 //Map filter 191 if ( (collection=(Collection)filters.get("maps"))==null || collection.isEmpty() || collection.contains(game.getMap().getPk())) 192 { 193 collection = null; 194 //StartDate filter 195 if( ((date=(Date)filters.get("startDate"))==null) || game.getDate().getTime() >= date.getTime() ) 196 { 197 date = null; 198 //EndDate Filter 199 if( ((date=(Date)filters.get("endDate"))==null) || game.getDate().getTime() <= date.getTime() ) 200 { 201 list.add(game); 202 } 203 } 204 } 205 } 206 207 return list; 208 } 209 210 public List getKills(Map filters) 211 { 212 if( filters==null || filters.isEmpty() ) return kills; 213 Date date = null; 214 Collection collection = null; 215 216 String weaponPk = (String)filters.get("weaponPk"); 217 List list = new ArrayList(); 218 219 for( Iterator games = this.games.values().iterator(); games.hasNext();) 220 { 221 Game game = (Game)games.next(); 222 223 //Map filter 224 if ( (collection=(Collection)filters.get("maps"))==null || collection.isEmpty() || collection.contains(game.getMap().getPk())) 225 { 226 collection = null; 227 //StartDate filter 228 if( ((date=(Date)filters.get("startDate"))==null) || game.getDate().getTime() >= date.getTime() ) 229 { 230 date = null; 231 //EndDate Filter 232 if( ((date=(Date)filters.get("endDate"))==null) || game.getDate().getTime() <= date.getTime() ) 233 { 234 for( Iterator rounds = game.getRounds().iterator(); rounds.hasNext();) 235 { 236 Round round = (Round)rounds.next(); 237 for( Iterator kills = round.getKills().iterator(); kills.hasNext();) 238 { 239 Kill kill = (Kill)kills.next(); 240 //WeaponPk Filter 241 if( weaponPk == null || kill.getWeapon().getPk().equals(weaponPk) ) 242 { 243 //Weapon Filter 244 if ( (collection=(Collection)filters.get("weapons"))==null || collection.isEmpty() || collection.contains(kill.getWeapon().getPk())) 245 { 246 247 //Player Filter 248 String killerPk = ((KillPlayer)kill.getPlayers().get("killer")).getPlayer().getPk(); 249 String victimPk = ((KillPlayer)kill.getPlayers().get("victim")).getPlayer().getPk(); 250 251 if ( (collection=(Collection)filters.get("players"))==null || collection.isEmpty() || (collection.contains(killerPk)&&collection.contains(victimPk)) ) 252 { 253 list.add(kill); 254 } 255 } 256 } 257 } 258 } 259 } 260 } 261 } 262 } 263 264 return list; 265 } 266 }

This page was automatically generated by Maven