: Class Person

Class Person

java.lang.Object
  |
  +--Person

public class Person
extends java.lang.Object

A Person object can communicate with other Persons.

The Person can send and receive simple textual messages.
The person can change his status to ONLINE, OFFLINE, BUSY or INVISIBLE.


Field Summary
static int BUSY
           
static int INVISIBLE
           
static int OFFLINE
           
static int ONLINE
           
 
Constructor Summary
Person(java.lang.String name)
          Creates a new person.
 
Method Summary
 java.lang.String getName()
          Returns the name of the person
 boolean receiveMessage(Person peer, java.lang.String message)
          Receives a message from a peer.
 boolean sendMessage(Person peer, java.lang.String message)
          Attempts to send a message to a peer.
 void setStatus(int status)
          Changes the status of the person.
 void setStatus(java.lang.String status)
          Changes the status of the person.
 java.lang.String toShortString()
          Returns a single line representation of the person.
 java.lang.String toString()
          Returns a String representation of the person.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONLINE

public static final int ONLINE

OFFLINE

public static final int OFFLINE

BUSY

public static final int BUSY

INVISIBLE

public static final int INVISIBLE
Constructor Detail

Person

public Person(java.lang.String name)
Creates a new person.

A new person is ONLINE.

Parameters:
name - The nane of the new perosn.
Method Detail

setStatus

public void setStatus(int status)
Changes the status of the person.

The status can be either: ONLINE, OFFLINE, BUSY, INVISIBLE.

Parameters:
status - The new status of the person.

setStatus

public void setStatus(java.lang.String status)
Changes the status of the person.

The status is one of the Strings: ONLINE, OFFLINE, BUSY, INVISIBLE

Parameters:
status - The new status of the person.

sendMessage

public boolean sendMessage(Person peer,
                           java.lang.String message)
Attempts to send a message to a peer.
Parameters:
peer - The Person who will receive the message.
message - The message to be sent.
Returns:
true if the message was sent and received successfully, i.e: if the peer is ONLINE, and the sender is not OFFLINE, false otherwise.

receiveMessage

public boolean receiveMessage(Person peer,
                              java.lang.String message)
Receives a message from a peer.

If the message can be displayed (based on the receiver's status), it is displayed in the following format: <Peer name> says: <message>
i.e: David says: hello world

The message can be displayed if the receiver is ONLINE.

Parameters:
peer - The Person who sent the message.
message - The message that was sent.
Returns:
true if the message is displayed by the receiver, false othewise (i.e: The receiving person is OFFLINE, BUSY...).

toString

public java.lang.String toString()
Returns a String representation of the person.
Returns:
A String representation of the person.
Overrides:
toString in class java.lang.Object

getName

public java.lang.String getName()
Returns the name of the person
Returns:
the name of the person

toShortString

public java.lang.String toShortString()
Returns a single line representation of the person.
Returns:
a single line representation of the person. The line is in the form: < name > : < status >