1 package org.argosfields.multi.server;
2
3 import java.io.Serializable;
4
5 import org.apache.commons.lang.NullArgumentException;
6 import org.apache.commons.lang.builder.HashCodeBuilder;
7 import org.apache.commons.lang.builder.ToStringBuilder;
8 import org.argosfields.multi.Player;
9
10 /***
11 * Session.java
12 * @author Xavier Cho
13 * @version $Revision: 1.2 $ $Date: 2004/04/17 18:21:02 $
14 */
15 public class Session implements Serializable {
16
17 private String sessionId;
18 private Player player;
19 private long lastCheckInTime;
20
21 /***
22 * @param sessionId
23 * @param userName
24 */
25 public Session(final String sessionId, final Player player) {
26 if (sessionId == null) {
27 throw new NullArgumentException("sessionId");
28 }
29
30 if (player == null) {
31 throw new NullArgumentException("player");
32 }
33
34 this.sessionId = sessionId;
35 this.player = player;
36
37 checkIn();
38 }
39
40 /***
41 * @return Returns the lastCheckInTime.
42 */
43 public long getLastCheckInTime() {
44 return lastCheckInTime;
45 }
46
47 /***
48 * @return Returns the sessionId.
49 */
50 public String getSessionId() {
51 return sessionId;
52 }
53
54 /***
55 * @return Returns the player.
56 */
57 public Player getPlayer() {
58 return player;
59 }
60
61 public void checkIn() {
62 this.lastCheckInTime = System.currentTimeMillis();
63 }
64
65 /***
66 * @see java.lang.Object#equals(java.lang.Object)
67 */
68 public boolean equals(final Object obj) {
69 if (obj instanceof Session) {
70 Session session = (Session) obj;
71 return sessionId.equals(session.sessionId)
72 && player.equals(session.player);
73 }
74
75 return false;
76 }
77
78 /***
79 * @see java.lang.Object#hashCode()
80 */
81 public int hashCode() {
82 HashCodeBuilder builder = new HashCodeBuilder();
83 builder.append(sessionId);
84 builder.append(player);
85
86 return builder.toHashCode();
87 }
88
89 /***
90 * @see java.lang.Object#toString()
91 */
92 public String toString() {
93 ToStringBuilder builder = new ToStringBuilder(this);
94 builder.append("sessionId", sessionId);
95 builder.append("player", player);
96
97 return builder.getStringBuffer().toString();
98 }
99 }
This page was automatically generated by Maven