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.Weapon; 22 import com.mlw.fps.model.business.vo.WeaponUsage; 23 import com.mlw.fps.model.business.vo.stats.WeaponStats; 24 import com.mlw.vlh.ValueList; 25 import com.mlw.vlh.ValueListAdapter; 26 import com.mlw.vlh.ValueListInfo; 27 import com.mlw.vlh.impl.DefaultValueList; 28 /*** 29 * 30 * @author Matthew Wilson 31 */ 32 public class PlayerWeaponStatsAdapter implements ValueListAdapter 33 { 34 35 /*** Creates a new instance of PlayerStatsAdapter */ 36 public PlayerWeaponStatsAdapter() 37 { 38 } 39 40 /*** This method tells the Service what still needs to be done on the 41 * Collection before returning the data. 42 * 43 * @return A bitwise or combination of DO_NOTHING, 44 * DO_SORT, DO_PAGE and DO_FILTER. For example:<br> 45 * <pre> 46 * public int getAdapterType(){ 47 * retuyrnDO_SORT && DO_PAGE; 48 * }</pre> 49 */ 50 public int getAdapterType() 51 { 52 return DO_SORT; 53 } 54 55 /*** Gets a ValueList 56 * @param info The <CODE>ValueList</CODE> information 57 * @param name The name of the <CODE>ValueList</CODE> 58 * @return The <CODE>ValueList</CODE> 59 */ 60 public ValueList getValueList(ValueListInfo info) 61 { 62 String killerPk = (String)info.getFilters().get("killerPk"); 63 64 Map stats = new HashMap(); 65 66 for( Iterator iter = StaticData.instance().getKills(info.getFilters()).iterator(); iter.hasNext();) 67 { 68 Kill kill = (Kill)iter.next(); 69 Weapon weapon = (Weapon)kill.getWeapon(); 70 Player killer = ((KillPlayer)kill.getPlayers().get("killer")).getPlayer(); 71 Player victim = ((KillPlayer)kill.getPlayers().get("victim")).getPlayer(); 72 73 WeaponStats ws = (WeaponStats) stats.get(weapon.getPk()); 74 if( ws==null) stats.put(weapon.getPk(), (ws = new WeaponStats(weapon)) ); 75 76 if( killer.getPk().equals(killerPk) ) 77 { 78 ws.addKills(1); 79 } 80 else if( victim.getPk().equals(killerPk) ) 81 { 82 ws.addDeaths(1); 83 } 84 } 85 86 87 for( Iterator iter = StaticData.instance().getGames(info.getFilters()).iterator(); iter.hasNext();) 88 { 89 Game game = (Game)iter.next(); 90 GameRecap recap = (GameRecap)game.getRecaps().get(killerPk); 91 92 if( recap != null ) 93 { 94 for(Iterator iter2 = recap.getWeaponUsage().values().iterator(); iter2.hasNext();) 95 { 96 WeaponUsage usage = (WeaponUsage)iter2.next(); 97 98 //Weapon Filter 99 Collection collection = null; 100 if ( (collection=(Collection)info.getFilters().get("weapons"))==null || collection.isEmpty() || collection.contains(usage.getWeapon().getPk())) 101 { 102 WeaponStats ws = (WeaponStats) stats.get(usage.getWeapon().getPk()); 103 if( ws==null) stats.put(usage.getWeapon().getPk(), (ws = new WeaponStats(usage.getWeapon())) ); 104 105 ws.add(usage); 106 } 107 } 108 } 109 } 110 111 return new DefaultValueList(new ArrayList(stats.values()), info); 112 } 113 114 }

This page was automatically generated by Maven