KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > wrd > Participants


1 package org.enhydra.shark.wrd;
2
3 import java.io.Serializable JavaDoc;
4 import java.util.*;
5
6 public class Participants extends HashMap implements Serializable JavaDoc, Cloneable JavaDoc {
7
8    public void addParticipant (String JavaDoc id) {
9       put(id,new Participant(id));
10    }
11
12    public Participant getParticipant (String JavaDoc id) {
13       return (Participant)get(id);
14    }
15
16    public Participant theBestScoreParticipant () {
17       Participant theBest=null;
18       Iterator it=values().iterator();
19       while (it.hasNext()) {
20          Participant p=(Participant)it.next();
21          if (theBest==null) {
22             theBest=p;
23             continue;
24          }
25          if (p.getScore()>theBest.getScore()) {
26             theBest=p;
27          }
28       }
29       return theBest;
30    }
31
32    public Object JavaDoc clone () {
33       try {
34          Participants ps=(Participants)super.clone();
35          ps.clear();
36          Iterator it=this.entrySet().iterator();
37          while (it.hasNext()) {
38             Map.Entry me=(Map.Entry)it.next();
39             ps.put(me.getKey(),((Participant)me.getValue()).clone());
40          }
41          return ps;
42       } catch (Exception JavaDoc ex) {
43          return null;
44       }
45    }
46
47 }
48
Popular Tags