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.List;
14 import java.util.Map;
15
16 import com.mlw.fps.model.business.dao.memmory.StaticData;
17 import com.mlw.fps.model.business.vo.Game;
18 import com.mlw.fps.model.business.vo.GameRecap;
19 import com.mlw.fps.model.business.vo.Kill;
20 import com.mlw.fps.model.business.vo.KillPlayer;
21 import com.mlw.fps.model.business.vo.Player;
22 import com.mlw.fps.model.business.vo.Weapon;
23 import com.mlw.fps.model.business.vo.WeaponUsage;
24 import com.mlw.fps.model.business.vo.stats.WeaponStats;
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 WeaponStatsAdapter implements ValueListAdapter
34 {
35
36 /*** Creates a new instance of PlayerStatsAdapter */
37 public WeaponStatsAdapter()
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 List kills = StaticData.instance().getKills(info.getFilters());
65 Long totalKills = new Long(kills.size());
66 for( Iterator iter = kills.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, totalKills)) );
75
76 ws.addKills(1);
77 }
78
79 for( Iterator iter = StaticData.instance().getGames(info.getFilters()).iterator(); iter.hasNext();)
80 {
81 Game game = (Game)iter.next();
82
83 for( Iterator iter2 = game.getRecaps().values().iterator(); iter2.hasNext();)
84 {
85 GameRecap recap = (GameRecap)iter2.next();
86 for(Iterator iter3 = recap.getWeaponUsage().values().iterator(); iter3.hasNext();)
87 {
88 WeaponUsage usage = (WeaponUsage)iter3.next();
89
90 //Weapon Filter
91 Collection collection = null;
92 if ( (collection=(Collection)info.getFilters().get("weapons"))==null || collection.isEmpty() || collection.contains(usage.getWeapon().getPk()))
93 {
94
95 WeaponStats ws = (WeaponStats) stats.get(usage.getWeapon().getPk());
96 if( ws==null) stats.put(usage.getWeapon().getPk(), (ws = new WeaponStats(usage.getWeapon())) );
97
98 ws.add(usage);
99 }
100 }
101 }
102 }
103
104 return new DefaultValueList(new ArrayList(stats.values()), info);
105 }
106
107 }
This page was automatically generated by Maven