vooga.users.user
Class VoogaUser

java.lang.Object
  extended by vooga.users.user.VoogaUser
All Implemented Interfaces:
java.io.Serializable

public class VoogaUser
extends java.lang.Object
implements java.io.Serializable

General class to represent functions required by a human VOOGA user. Provides ways to alter and get information about the internal data structures specific to the user such as favorite games, friends, logged in status, saved games etc. Two users cannot have the same name, an invariant maintained by the UserDatabase class.

 VOOGAUser user1 = new VOOGAUser("user1");
 
creates a new VOOGAUser with name "user1".
 user1.getUserAvatar()
 
returns the Avatar associated with user1. Now consider the following example:
 VoogaUser user1 = new VoogaUser("user1");
 VoogaUser user2 = new VoogaUser("user1");
 
will never be called. The database will check to make sure that a given username is not taken before creating an User object. Constructors are protected because only the Database should be able to create new users (User doesn't know about the database so there is no checking to see if "name" is already the name of another User) For testing purposes, should you need to gain access to a VoogaUser, please use the following workaround:
 UserDatabase db = new UserDatabase();
 db.addUser("name", "password");
 VoogaUser user = db.getUser("name");
 
and then go on as planned with user.

Version:
1.2
Author:
Alex Edelsburg, Matt Prorok, Stephanie Chang
See Also:
Serialized Form

Nested Class Summary
static class VoogaUser.GameListFilter
           
 
Constructor Summary
protected VoogaUser(java.rmi.server.UID uid, java.lang.String name)
          Constructor for a new user with name specified by name.
protected VoogaUser(java.rmi.server.UID uid, java.lang.String name, java.lang.String password)
          Constructor for a new user with name specified by name.
protected VoogaUser(java.rmi.server.UID uid, java.lang.String name, java.lang.String password, java.lang.String recoveryQuestion, java.lang.String recoveryAnswer)
          Constructor for a new user with the following properties.
 
Method Summary
 void addFriend(VoogaUser friend)
          adds friend to this user's list of friends
 void addGameStats(java.lang.String gameName)
          adds the specified game to the myGameStats map
 void addToFavorites(java.lang.String gameName)
          adds this game to the list of favorites
protected  void changeName(java.lang.String newname)
          changes the name associated with this user.
protected  boolean changePassword(java.lang.String oldPassword, java.lang.String newPassword)
          Returns true if the conversion from oldPassword to newPassword is successful, false otherwise.
 boolean equals(java.lang.Object o)
           
 java.lang.String getAboutMeText()
          Returns this user's "about me text"
 java.util.List<java.lang.String> getAchievements(java.lang.String gameName)
          gets the achievements for this user for the specified game
 java.util.Collection<java.lang.String> getFavoriteGames()
          Gets this user's list of favorite games
 java.util.Set<java.lang.String> getFriendList()
          Returns an unmodifiable set view of this user's friends
 java.util.Collection<AbstractVoogaReplay> getGameSaves(java.lang.String gameName)
          Returns a Collection of all the AbstractGames associated with game for this user
 int getHighScore(java.lang.String gameName)
          Returns this VoogaUser's high score for game.
protected  java.lang.String getRecoveryQuestion()
          Returns this user's recovery question
 java.rmi.server.UID getUID()
          Returns the UID(unique identifier) associated with this user
 java.awt.image.BufferedImage getUserAvatar()
           
 java.lang.String getUsername()
          Returns a String that is this user's username
 boolean isLoggedIn()
           
protected  boolean isPasswordValid(java.lang.String password)
          Returns true if password is the correct password for this user
 boolean multipleGamesAllowed()
          Returns true if multiple games are allowed for this VoogaUser.
 void recordHighScore(int score, java.lang.String gameName)
          Checks to see if score is a new high score for this user and if so, sets score as the high score.
protected  boolean recoverPassword(java.lang.String securityAnswer, java.lang.String newPassword)
          Returns true if the user's password was successfully changed
 void removeFriend(VoogaUser friend)
          removes friend from this user's list of friends
 void removeFromFavorites(java.lang.String gameName)
          remove this game from the list of favorites
protected  void setAboutMeText(java.lang.String aboutMeText)
          Sets this user's "about me" text
 void setLoggedIn()
          sets the logged in status of this user to be false.
 void setLoggedOut()
          sets the logged in status of this user to be false
 void setMultipleGamesAllowed(boolean allowMultipleGames)
          Sets the allowMultipleGames status for this VoogaUser
protected  void setRecoveryAnswer(java.lang.String answer)
          Sets this user's recovery answer to this new value
protected  void setRecoveryQuestion(java.lang.String question)
          Sets this user's recovery question to this new value
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VoogaUser

protected VoogaUser(java.rmi.server.UID uid,
                    java.lang.String name)
Constructor for a new user with name specified by name. Initializes all internal data structures

Parameters:
name - the name of the new user

VoogaUser

protected VoogaUser(java.rmi.server.UID uid,
                    java.lang.String name,
                    java.lang.String password)
Constructor for a new user with name specified by name. Initializes all internal data structures.

Parameters:
uid - the UID to associate with this user
name - the name of the new user
password - the password of the new user

VoogaUser

protected VoogaUser(java.rmi.server.UID uid,
                    java.lang.String name,
                    java.lang.String password,
                    java.lang.String recoveryQuestion,
                    java.lang.String recoveryAnswer)
Constructor for a new user with the following properties.

Parameters:
uid - the UID to associate with this user
name - the name of the new user
password - the password of the new user
recoveryQuestion - the question the human will be asked to reset the password
recoveryAnswer - the answer that will allow the human to reset the password
Method Detail

getUsername

public java.lang.String getUsername()
Returns a String that is this user's username

Returns:
a String that is this user's username

multipleGamesAllowed

public boolean multipleGamesAllowed()
Returns true if multiple games are allowed for this VoogaUser.

Returns:
the boolean status of whether or not multiple concurrent games are allowed

setMultipleGamesAllowed

public void setMultipleGamesAllowed(boolean allowMultipleGames)
Sets the allowMultipleGames status for this VoogaUser

Parameters:
allowMultipleGames - true if multiple games are to be allowed for this user, false otherwise

getUserAvatar

public java.awt.image.BufferedImage getUserAvatar()
Returns:
a BufferedImage representing this user's avatar

isPasswordValid

protected boolean isPasswordValid(java.lang.String password)
Returns true if password is the correct password for this user

Parameters:
password - the password to verify
Returns:
true if the provided password is correct, false otherwise

getUID

public java.rmi.server.UID getUID()
Returns the UID(unique identifier) associated with this user

Returns:
the UID(unique identifier) associated with this user

changePassword

protected boolean changePassword(java.lang.String oldPassword,
                                 java.lang.String newPassword)
Returns true if the conversion from oldPassword to newPassword is successful, false otherwise.

Parameters:
oldPassword - the current password for this user
newPassword - the user's new password
Returns:
true if the password change is successful, false if not

isLoggedIn

public boolean isLoggedIn()
Returns:
true if this user is currently logged in

getFriendList

public java.util.Set<java.lang.String> getFriendList()
Returns an unmodifiable set view of this user's friends

Returns:
an unmodifiable set view of this user's friends

addGameStats

public void addGameStats(java.lang.String gameName)
adds the specified game to the myGameStats map

Parameters:
game - the game to add to the map

addToFavorites

public void addToFavorites(java.lang.String gameName)
adds this game to the list of favorites

Parameters:
gameName - the game being added to the favorites list

removeFromFavorites

public void removeFromFavorites(java.lang.String gameName)
remove this game from the list of favorites

Parameters:
gameName - the game being remove from the favorites list

setLoggedOut

public void setLoggedOut()
sets the logged in status of this user to be false


setLoggedIn

public void setLoggedIn()
sets the logged in status of this user to be false.


getGameSaves

public java.util.Collection<AbstractVoogaReplay> getGameSaves(java.lang.String gameName)
Returns a Collection of all the AbstractGames associated with game for this user

Parameters:
game - the game for which the caller wants the AbstractGames
Returns:
a Collection of all the AbstractGames associated with game for this user

getFavoriteGames

public java.util.Collection<java.lang.String> getFavoriteGames()
Gets this user's list of favorite games

Returns:
a Collection of the user's favorite games

changeName

protected void changeName(java.lang.String newname)
changes the name associated with this user. Relies on the caller to verify that the name change is allowed (ie. that no other user has newname as its name)

Parameters:
newname - the new name of this user

getAchievements

public java.util.List<java.lang.String> getAchievements(java.lang.String gameName)
gets the achievements for this user for the specified game

Parameters:
game - the game for which achievements are desired
Returns:
a List of strings representing the achievements

getHighScore

public int getHighScore(java.lang.String gameName)
Returns this VoogaUser's high score for game. If a score has not yet been recorded for this AbstractGame and this user, this method will return 0.

Parameters:
game - the game being queried
Returns:
the high score associated with game

recordHighScore

public void recordHighScore(int score,
                            java.lang.String gameName)
Checks to see if score is a new high score for this user and if so, sets score as the high score.

Parameters:
score - the score to report for this user
game - the game associated with the given score

addFriend

public void addFriend(VoogaUser friend)
adds friend to this user's list of friends

Parameters:
friend - the user to add as a friend

removeFriend

public void removeFriend(VoogaUser friend)
removes friend from this user's list of friends

Parameters:
friend - the user to remove as a friend

equals

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getRecoveryQuestion

protected java.lang.String getRecoveryQuestion()
Returns this user's recovery question

Returns:
this user's recovery question

recoverPassword

protected boolean recoverPassword(java.lang.String securityAnswer,
                                  java.lang.String newPassword)
Returns true if the user's password was successfully changed

Parameters:
securityAnswer - the human's answer
newPassword - the human's new password
Returns:
true if the answer was correct & the password was changed

setRecoveryQuestion

protected void setRecoveryQuestion(java.lang.String question)
Sets this user's recovery question to this new value

Parameters:
question - the new recovery question

setRecoveryAnswer

protected void setRecoveryAnswer(java.lang.String answer)
Sets this user's recovery answer to this new value

Parameters:
answer - the new recovery answer

setAboutMeText

protected void setAboutMeText(java.lang.String aboutMeText)
Sets this user's "about me" text

Parameters:
aboutMeText - the user's "about me" information

getAboutMeText

public java.lang.String getAboutMeText()
Returns this user's "about me text"

Returns:
"about me" text