common
Class ContactList

java.lang.Object
  extended by common.ContactList
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ContactList
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

A representation of a user's contact list.

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

Field Summary
private static long serialVersionUID
           
(package private)  java.util.Vector<User> vector
           
 
Constructor Summary
ContactList()
          Creates a new empty contact list.
 
Method Summary
 boolean accepts(User user)
          Checks if the contact list accepts messages from a user given by argument.
 void addUser(User user, boolean friend)
          Adds a User nickname to the contact list.
 ContactList clone()
           
 boolean contains(User user)
           
 int getSize()
           
 User getUser(int i)
           
 User getUser(java.lang.String name)
           
 boolean removeUser(User user)
          Removes a User from the contact list.
 void setFriend(User user, boolean friend)
          Sets a contact status.
 void setOnLine(User user, boolean online)
          Sets a contact status.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

vector

java.util.Vector<User> vector
Constructor Detail

ContactList

public ContactList()
Creates a new empty contact list.

Method Detail

contains

public boolean contains(User user)
Parameters:
user - the user to search for.
Returns:
true only if the user given by argument is contained in the contact list.

addUser

public void addUser(User user,
                    boolean friend)
             throws UserAlreadyInsertedException
Adds a User nickname to the contact list. The User passed by argument is copied. The new User state is offline. When the friend boolean is true, if the user is contained in the list but is not friend, it becomes friend.

Parameters:
user - the User to add
friend - true if the user to add accepts messages from the user owning Contact List.
Throws:
UserAlreadyInsertedException - if the user is already present and its friendness does not change.

removeUser

public boolean removeUser(User user)
Removes a User from the contact list.

Parameters:
user - the User to delete
Returns:
true if the user were removed, false otherwise (not present).

getUser

public User getUser(int i)
Parameters:
i - the user id.
Returns:
a user of the index given as argument.

getUser

public User getUser(java.lang.String name)
Parameters:
name - the nickname.
Returns:
the user whose nickname equals the one given by argument, or null if such a user does not exist.

accepts

public boolean accepts(User user)
Checks if the contact list accepts messages from a user given by argument.

Parameters:
user - the user
Returns:
true if and only if the contact list accepts messages from the user.

getSize

public int getSize()
Returns:
the number of users contained into the contact list.

setFriend

public void setFriend(User user,
                      boolean friend)
Sets a contact status. If the contact is not present in the list, it is added.

Parameters:
user - the contact to change status of.
friend - true if the contact status must be set to friend, false if the contact must be blocked.

setOnLine

public void setOnLine(User user,
                      boolean online)
Sets a contact status.

Parameters:
user - the contact to change status of.
online - true if the contatc is online, else false.

clone

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