blather.controller
Class UserController

java.lang.Object
  extended by blather.controller.UserController
All Implemented Interfaces:
UserControllerInterface

public class UserController
extends java.lang.Object
implements UserControllerInterface

UserController provides a mechanism to access and update details of an individual Blather user.


Constructor Summary
UserController(BlatherUserInterface user, java.lang.String sessionID, UserDB udb, SessionDB sdb)
          Creates a new UserController with the given BlatherUser and the given session ID.
 
Method Summary
 boolean changeEmail(java.lang.String newEmail)
          Changes this user's profile email address.
 BlabInterface[] getAllBlabs()
          Returns an array consisting of all of this user's blabs, sorted in reverse chronological order.
 BlabInterface[] getAllFriendBlabs()
          Returns an array consisting of all of this user's friends' blabs, sorted in reverse chronological order.
 java.lang.String getEmail()
          If this UserController's session ID is valid, return a string representation of this user's full email address.
 BlatherUserInterface[] getFriends()
          Returns an array of this user's friends.
 BlabInterface[] getSomeBlabs(int howMany)
          Returns an array consisting of some of this user's blabs, sorted in reverse chronological order.
 BlabInterface[] getSomeFriendBlabs(int howMany)
          Returns an array consisting of some of this user's friends' blabs, sorted in reverse chronological order.
 java.lang.String getUsername()
          Returns this user's username.
 boolean newBlab(java.lang.String blabContent)
          Creates a new blab for this user with the given content, with a timestamp of now, and adds this blab to the list of user blabs.
 boolean newFriend(java.lang.String username)
          Adds a friend to the list of users that this user is tracking.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserController

public UserController(BlatherUserInterface user,
                      java.lang.String sessionID,
                      UserDB udb,
                      SessionDB sdb)
Creates a new UserController with the given BlatherUser and the given session ID.

Parameters:
user - the user we'd like to access
sessionID - the session ID of the user who is currently accessing the application
udb - the UserDB from the AppController
sdb - the SessionDB from the AppController
Method Detail

getAllBlabs

public BlabInterface[] getAllBlabs()
Description copied from interface: UserControllerInterface
Returns an array consisting of all of this user's blabs, sorted in reverse chronological order. (Hint: the BlabUtil class provides a method to sort an array of blabs in chronological order.)

Specified by:
getAllBlabs in interface UserControllerInterface
Returns:

getSomeBlabs

public BlabInterface[] getSomeBlabs(int howMany)
Description copied from interface: UserControllerInterface
Returns an array consisting of some of this user's blabs, sorted in reverse chronological order. (Hint: the BlabUtil class provides a method to sort an array of blabs in chronological order.)

Specified by:
getSomeBlabs in interface UserControllerInterface
Parameters:
howMany - the number of blabs to put in the array, starting with the most recent
Returns:

getAllFriendBlabs

public BlabInterface[] getAllFriendBlabs()
Description copied from interface: UserControllerInterface
Returns an array consisting of all of this user's friends' blabs, sorted in reverse chronological order. (Hint: the BlabUtil class provides a method to sort an array of blabs in chronological order.)

Specified by:
getAllFriendBlabs in interface UserControllerInterface
Returns:

getSomeFriendBlabs

public BlabInterface[] getSomeFriendBlabs(int howMany)
Description copied from interface: UserControllerInterface
Returns an array consisting of some of this user's friends' blabs, sorted in reverse chronological order. (Hint: the BlabUtil class provides a method to sort an array of blabs in chronological order.)

Specified by:
getSomeFriendBlabs in interface UserControllerInterface
Parameters:
howMany - the number of blabs to put in the array, starting with the most recent
Returns:

changeEmail

public boolean changeEmail(java.lang.String newEmail)
Description copied from interface: UserControllerInterface
Changes this user's profile email address. Preconditions: (1) this UserController's Session ID must exist, (2) it must indicate that the user who is logged in is the same as the user we are changing the email for, and (3) newEmail must be a valid address.

Specified by:
changeEmail in interface UserControllerInterface
Returns:
true on success, false on failure

newBlab

public boolean newBlab(java.lang.String blabContent)
Description copied from interface: UserControllerInterface
Creates a new blab for this user with the given content, with a timestamp of now, and adds this blab to the list of user blabs. Preconditions: (1) this UserController's Session ID must exist, and (2) it must indicate that the user who is logged in is the same as the user we are adding a blab for.

Specified by:
newBlab in interface UserControllerInterface
Returns:
true on success, false on failure

newFriend

public boolean newFriend(java.lang.String username)
Description copied from interface: UserControllerInterface
Adds a friend to the list of users that this user is tracking. Preconditions: (1) this UserController's Session ID must exist, (2) it must indicate that the user who is logged in is the same as the user we are adding a friend for, and (3) username must be a valid username.

Specified by:
newFriend in interface UserControllerInterface
Returns:
true on success, false on failure

getUsername

public java.lang.String getUsername()
Description copied from interface: UserControllerInterface
Returns this user's username.

Specified by:
getUsername in interface UserControllerInterface
Returns:

getEmail

public java.lang.String getEmail()
Description copied from interface: UserControllerInterface
If this UserController's session ID is valid, return a string representation of this user's full email address. Otherwise, return a "sanitized" email address (using getDisplayEmail()). The idea is that we want to let people browse users and blabs without logging in, but not harvest email addresses for spam.

Specified by:
getEmail in interface UserControllerInterface
Returns:
a string representation of an email address (possibly obscured)

getFriends

public BlatherUserInterface[] getFriends()
Description copied from interface: UserControllerInterface
Returns an array of this user's friends.

Specified by:
getFriends in interface UserControllerInterface
Returns:
an array of this user's friends.