1 20 21 package freecs.util; 22 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Vector ; 28 29 import freecs.Server; 30 import freecs.content.MessageState; 31 import freecs.core.Group; 32 import freecs.core.User; 33 34 39 public class GroupUserList { 40 HashMap ht = new HashMap (); 41 public GroupUserList () { 42 if (Server.TRACE_CREATE_AND_FINALIZE) 43 Server.log (this, "++++++++++++++++++++++++++++++++++++++++CREATE", Server.MSG_STATE, Server.LVL_VERY_VERBOSE); 44 } 45 46 public void addUser (User u) { 47 Group g = u.getGroup(); 48 Vector v = (Vector ) ht.get(g); 49 if (v == null) 50 v = new Vector (); 51 v.addElement(u); 52 ht.put(g,v); 53 } 54 55 public Iterator iterator () { 56 return ht.values().iterator(); 57 } 58 59 public void sendMessage (MessageState ms, String tpl, boolean target) { 60 String singular = tpl + ".singular"; 61 String plural = tpl + ".plural"; 62 ms.useRenderCache=false; 63 List l = new ArrayList (); 64 for (int i = 0; i < ms.usrList.length; i++) 65 l.add(ms.usrList[i]); 66 l.add(ms.sender); 67 for (Iterator i = ht.keySet().iterator(); i.hasNext(); ) { 68 Group g = (Group) i.next(); 69 Vector v = (Vector ) ht.get(g); 70 if (v == null || v.size()==0) 71 continue; 72 if (v.size()==1) { 73 ms.msgTemplate=singular; 74 ms.usercontext = (User) v.get(0); 75 } else if (v.size() > 1) { 76 ms.usrList = v.toArray(); 77 ms.msgTemplate=plural; 78 } 79 if (target) { 80 ms.targetGroup = g; 81 g.exclusiveSendMessage(ms.mp, l); 82 } else { 83 ms.sourceGroup = g; 84 g.exclusiveSendMessage(ms.mp, l); 85 } 86 } 87 } 88 89 public void finalize() { 90 if (Server.TRACE_CREATE_AND_FINALIZE) 91 Server.log(this, "----------------------------------------FINALIZED", Server.MSG_STATE, Server.LVL_VERY_VERBOSE); 92 } 93 } | Popular Tags |