View Javadoc

1   /*
2    * AI Soccer Project - network gaming environment for AI warriors.
3    * Copyright (C) 2001-2004  Marcin Werla, Pawel Widera
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, you can find it here:
17   * http://www.gnu.org/licenses/gpl.html
18   */
19  
20  package snifos.common;
21  
22  
23  /***
24   * This class represents id of a user in SNIFOS system.
25   * @version $Id: UserId.java,v 1.2 2004/05/08 21:55:29 mwerla Exp $
26   */
27  public class UserId {
28      private int commModuleId;
29      private int userIdInModule;
30      private String userId;
31  
32      /***
33       * Creates new instance of UserId class.
34       * @param commModuleId Communication module to which user is connected.
35       * @param userIdInModule User id unique for the communication module
36       * to which user is connected.
37       */
38      public UserId(int commModuleId, int userIdInModule) {
39          this.commModuleId = commModuleId;
40          this.userIdInModule = userIdInModule;
41          this.userId = commModuleId + "|" + userIdInModule;
42      }
43  
44      /***
45       * Checks equality of two user ids.
46       * @see java.lang.Object#equals(java.lang.Object)
47       * @param that UserId to compare.
48       * @return True if both ids represent the same user, otherwise false.
49       */
50      public boolean equals(UserId that) {
51          return (that != null) ? that.userId.equals(this.userId) : false;
52      }
53  
54      /***
55       * Returns user id hashcode.
56       * @return Hash code of user id - baesd on its string representation.
57       */
58      public int hashCode() {
59          return userId.hashCode();
60      }
61  
62      /***
63       * Returns string representation of this UserId instance.
64       * @return commModuleId + "|" + userIdInModule
65       */
66      public String toString() {
67          return userId;
68      }
69  
70      /***
71       * Getter for commModuleId field.
72       * @see #UserId(int, int)
73       * @return commModuleId
74       */
75      public int getCommModuleId() {
76          return commModuleId;
77      }
78  
79      /***
80       * Returns string representation of this UserId instance.
81       * @return commModuleId + "|" + userIdInModule
82       */
83      public String getUserId() {
84          return userId;
85      }
86  
87      /***
88       * Getter for userIdInModule field.
89       * @see #UserId(int, int)
90       * @return userIdInModule
91       */
92      public int getUserIdInModule() {
93          return userIdInModule;
94      }
95  }