1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package aigames.soccer.application;
21
22 import org.dom4j.Document;
23
24 import snifos.common.UserId;
25
26 import java.util.Calendar;
27 import java.util.GregorianCalendar;
28
29
30 /***
31 *
32 * @version $Id: UserInfo.java,v 1.4 2004/05/08 21:55:27 mwerla Exp $
33 */
34 public class UserInfo {
35 /*** Unknown type of user */
36 public static final int TYPE_UNKNOWN = 0;
37
38 /*** PLAYER type of user */
39 public static final int TYPE_PLAYER = 1;
40
41 /*** OBSERVER type of user */
42 public static final int TYPE_OBSERVER = 2;
43 private UserId userId;
44 private String name = "";
45 private int noOfBadMessages = 0;
46 private Calendar lastMessageDate = new GregorianCalendar();
47 private int type = TYPE_UNKNOWN;
48
49 /***
50 * Constructor with user id.
51 * @param userId User id for the user info.
52 */
53 public UserInfo(UserId userId) {
54 this.userId = userId;
55 }
56
57 /***
58 * Constructor which sets user id and reads user type from message.
59 * @param userId User id for the user info.
60 * @param message Message with user type.
61 */
62 public UserInfo(UserId userId, Document message) {
63 this(userId);
64
65 String type = message.selectSingleNode("//message/mod-type").getText();
66
67 if ("player".equals(type)) {
68 this.type = TYPE_PLAYER;
69 } else if ("observer".equals(type)) {
70 this.type = TYPE_OBSERVER;
71 }
72
73 this.name = message.selectSingleNode("//message/name").getText();
74 }
75
76 /***
77 * Returns user type.
78 * @return User type.
79 */
80 public int getType() {
81 return type;
82 }
83
84 /***
85 * Sets user type.
86 * @param type User type to set.
87 */
88 public void setType(int type) {
89 this.type = type;
90 }
91
92 /***
93 * Returns last user message date.
94 * @return Last user message date
95 */
96 public Calendar getLastMessageDate() {
97 return lastMessageDate;
98 }
99
100 /***
101 * Sets last user message date.
102 * @param lastMessageDate Last message date to set.
103 */
104 public void setLastMessageDate(Calendar lastMessageDate) {
105 this.lastMessageDate = lastMessageDate;
106 }
107
108 /***
109 * Gets user name.
110 * @return User name.
111 */
112 public String getName() {
113 return name;
114 }
115
116 /***
117 * Sets user name.
118 * @param name User name to set.
119 */
120 public void setName(String name) {
121 this.name = name;
122 }
123
124 /***
125 * Returns number of bad messages recieved from user.
126 * @return Number of bad messages recieved from user.
127 */
128 public int getNoOfBadMessages() {
129 return noOfBadMessages;
130 }
131
132 /***
133 * Sets number of bad messages recieved from user.
134 * @param noOfBadMessages Number of bad messages to set.
135 */
136 public void setNoOfBadMessages(int noOfBadMessages) {
137 this.noOfBadMessages = noOfBadMessages;
138 }
139
140 /***
141 * Returns user id.
142 * @return User id.
143 */
144 public UserId getUserId() {
145 return userId;
146 }
147 }