001 /*
002
003 $Id: ExistingUserResponse.java,v 1.4 2003/03/24 18:22:32 culdesac Exp $
004
005 */
006
007 package sharpster.common;
008
009 import sharpster.common.Response;
010 import java.io.Serializable;
011 import java.util.LinkedList;
012
013 /**
014 * A response containing information about the users which are
015 * available on the network.
016 */
017 public class ExistingUserResponse extends Response implements Serializable {
018
019 /**
020 * A list of existing users.
021 */
022 private LinkedList existingUsers;
023
024 /**
025 *
026 */
027 public ExistingUserResponse() {
028 existingUsers = new LinkedList();
029 }
030
031 /**
032 * Returns the type of this response.
033 */
034 public int getType() {
035 return sharpster.common.ResponseType.EXISTING_USER;
036 }
037
038 /**
039 * Returns the users which are available on the network.
040 *
041 * @return An array containing existing users.
042 */
043 public String[] getExistingUsers() {
044 return (String[])existingUsers.toArray();
045 }
046
047 /**
048 * Sets the users which are available on the network.
049 *
050 * @param users An array containing users.
051 */
052 public void addExistingUsers(String user) {
053 existingUsers.add(new String(user));
054 }
055
056 /**
057 *
058 */
059 public void setExistingUsers(String[] users) {
060 existingUsers.clear();
061 for(int i=0;i<users.length;i++) {
062 existingUsers.add(users[i]);
063 }
064 }
065
066 public String toString() {
067 String msg = super.toString();
068
069 msg = "Existing user response\n" + msg;
070 msg += "- Users: ";
071
072 for(int i=0;i<existingUsers.size();i++) {
073 String user = (String)existingUsers.get(i);
074 if(user != null) {
075 msg += user + "\n ";
076 }
077 }
078
079 return msg;
080 }
081 }