View Javadoc
1 /* 2 * PlayerStatsAdapter.java 3 * 4 * Created on April 24, 2003, 12:30 AM 5 */ 6 7 package com.mlw.fps.model.business.dao.memmory.vlh; 8 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.HashMap; 12 import java.util.Iterator; 13 import java.util.Map; 14 15 import com.mlw.fps.model.business.dao.memmory.StaticData; 16 import com.mlw.fps.model.business.vo.Game; 17 import com.mlw.fps.model.business.vo.GameRecap; 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.Player; 21 import com.mlw.fps.model.business.vo.PlayerStatus; 22 import com.mlw.fps.model.business.vo.Round; 23 import com.mlw.fps.model.business.vo.WeaponUsage; 24 import com.mlw.fps.model.business.vo.stats.PlayerStats; 25 import com.mlw.vlh.ValueList; 26 import com.mlw.vlh.ValueListAdapter; 27 import com.mlw.vlh.ValueListInfo; 28 import com.mlw.vlh.impl.DefaultValueList; 29 /*** 30 * 31 * @author Matthew Wilson 32 */ 33 public class PlayerStatsAdapter implements ValueListAdapter 34 { 35 36 /*** Creates a new instance of PlayerStatsAdapter */ 37 public PlayerStatsAdapter() 38 { 39 } 40 41 /*** This method tells the Service what still needs to be done on the 42 * Collection before returning the data. 43 * 44 * @return A bitwise or combination of DO_NOTHING, 45 * DO_SORT, DO_PAGE and DO_FILTER. For example:<br> 46 * <pre> 47 * public int getAdapterType(){ 48 * retuyrnDO_SORT && DO_PAGE; 49 * }</pre> 50 */ 51 public int getAdapterType() 52 { 53 return DO_SORT; 54 } 55 56 /*** Gets a ValueList 57 * @param info The <CODE>ValueList</CODE> information 58 * @param name The name of the <CODE>ValueList</CODE> 59 * @return The <CODE>ValueList</CODE> 60 */ 61 public ValueList getValueList(ValueListInfo info) 62 { 63 Map stats = new HashMap(); 64 65 for( Iterator iter = StaticData.instance().getKills(info.getFilters()).iterator(); iter.hasNext();) 66 { 67 Kill kill = (Kill)iter.next(); 68 Player killer = ((KillPlayer)kill.getPlayers().get("killer")).getPlayer(); 69 Player victim = ((KillPlayer)kill.getPlayers().get("victim")).getPlayer(); 70 71 PlayerStats kvo = (PlayerStats)stats.get(killer.getPk()); 72 if( kvo==null) stats.put(killer.getPk(), (kvo = new PlayerStats(killer, victim)) ); 73 kvo.getWeapon().addKills(1); 74 75 PlayerStats vvo = (PlayerStats)stats.get(victim.getPk()); 76 if( vvo==null) stats.put(victim.getPk(), (vvo = new PlayerStats(victim, killer)) ); 77 vvo.getWeapon().addDeaths(1); 78 } 79 80 for( Iterator iter = StaticData.instance().getGames(info.getFilters()).iterator(); iter.hasNext();) 81 { 82 Game game = (Game)iter.next(); 83 84 for(Iterator rounds = game.getRounds().iterator(); rounds.hasNext();) 85 { 86 Round round = (Round)rounds.next(); 87 for(Iterator players = round.getStatusOfPlayers().values().iterator(); players.hasNext();) 88 { 89 PlayerStatus status = (PlayerStatus)players.next(); 90 91 PlayerStats ps = (PlayerStats)stats.get(status.getPlayer().getPk()); 92 if( ps!=null ) 93 { 94 95 ps.addSecondsAlive( status.getSecondsAlive() ); 96 ps.addSecondsPlaying( round.getLength() ); 97 } 98 } 99 } 100 101 for( Iterator iter2 = game.getRecaps().keySet().iterator(); iter2.hasNext();) 102 { 103 String key = (String)iter2.next(); 104 GameRecap recap = (GameRecap)game.getRecaps().get(key); 105 for(Iterator iter3 = recap.getWeaponUsage().values().iterator(); iter3.hasNext();) 106 { 107 WeaponUsage usage = (WeaponUsage)iter3.next(); 108 109 //WeaponPk filter 110 String weaponPk = (String)info.getFilters().get("weaponPk"); 111 if( weaponPk == null || usage.getWeapon().getPk().equals(weaponPk) ) 112 { 113 //Weapon Filter 114 Collection collection = null; 115 if ( (collection=(Collection)info.getFilters().get("weapons"))==null || collection.isEmpty() || collection.contains(usage.getWeapon().getPk())) 116 { 117 PlayerStats ps = (PlayerStats)stats.get(key); 118 if( ps!=null ) 119 { 120 ps.getWeapon().add(usage); 121 } 122 } 123 } 124 } 125 } 126 } 127 128 return new DefaultValueList(new ArrayList(stats.values()), info); 129 } 130 131 }

This page was automatically generated by Maven