common
Class User

java.lang.Object
  extended by common.User
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.lang.Object>
Direct Known Subclasses:
ManagedUser

public class User
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.lang.Object>

A representatin of a Gossip user.

Author:
Marco Cornolti and Alessandro Franchini
See Also:
Serialized Form

Field Summary
private  int connection
           
private  java.lang.Boolean friend
           
private  java.net.InetAddress ip
           
private  java.lang.String nick
           
private  int port
           
private static long serialVersionUID
           
private  java.lang.Boolean state
           
 
Constructor Summary
User(java.lang.String name, java.net.InetAddress ip, int port, java.lang.Boolean state, java.lang.Boolean friend)
           
 
Method Summary
 User clone()
           
 int compareTo(java.lang.Object usr2)
          Compares this user (usr1) with usr2 by their nicknames.
 boolean equals(java.lang.Object u2)
           
 int getConn()
           
 java.net.InetAddress getIP()
           
 java.lang.String getNick()
           
 int getPort()
           
 java.lang.Boolean isFriend()
           
 boolean isOnline()
           
 void setConn(int status)
          Sets the connection number.
 void setFriend(java.lang.Boolean friend)
          Sets the user friendness.
 void setIp(java.net.InetAddress ip)
          Sets the user IP address.
 void setName(java.lang.String name)
          Sets the name of this user.
 void setOnline(boolean state)
          Sets the user state.
 void setPort(int port)
          Sets the TCP port of the user.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

nick

private java.lang.String nick

ip

private java.net.InetAddress ip

port

private int port

state

private java.lang.Boolean state

friend

private java.lang.Boolean friend

connection

private int connection
Constructor Detail

User

public User(java.lang.String name,
            java.net.InetAddress ip,
            int port,
            java.lang.Boolean state,
            java.lang.Boolean friend)
Parameters:
name - the user's nickname.
ip - the users' ip.
port - the user's TCP port.
state - the user's state (true if online).
friend - true if the user is a friend (only needed if the user is contained in a contact list)
Method Detail

equals

public boolean equals(java.lang.Object u2)
Overrides:
equals in class java.lang.Object

getNick

public java.lang.String getNick()
Returns:
the user nickname.

getIP

public java.net.InetAddress getIP()
Returns:
the user's IP address.

getPort

public int getPort()
Returns:
the user TCP port.

setName

public void setName(java.lang.String name)
Sets the name of this user.

Parameters:
name - the name.

setPort

public void setPort(int port)
Sets the TCP port of the user.

Parameters:
port - the user port.

setIp

public void setIp(java.net.InetAddress ip)
Sets the user IP address.

Parameters:
ip -

isOnline

public boolean isOnline()
Returns:
true only if the user is on-line.

isFriend

public java.lang.Boolean isFriend()
Returns:
true if the user is a friend (only if contained in a contact list)

setOnline

public void setOnline(boolean state)
Sets the user state.

Parameters:
state - true if on-line, false if off-line.

setFriend

public void setFriend(java.lang.Boolean friend)
Sets the user friendness. (only considered if the user is contained in a contact list)

Parameters:
friend - the user friendness.

getConn

public int getConn()
Returns:
the connection number.

setConn

public void setConn(int status)
Sets the connection number.

Parameters:
status - the connection number.

clone

public User clone()
Overrides:
clone in class java.lang.Object

compareTo

public int compareTo(java.lang.Object usr2)
Compares this user (usr1) with usr2 by their nicknames.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>
Parameters:
usr2 - the user to compare to.
Returns:
>0 if the usr2 comes alphabetically after usr1, 0 if their name are the same, less than 0 otherwise.