usflix
Class UserDatabase

java.lang.Object
  extended by usflix.UserDatabase

public class UserDatabase
extends java.lang.Object

UserDatabase class manages user database, and provides user account related methods.

Version:
4.0 April 3, 2013.
Author:
EJ Jung

Field Summary
static int minPwdLength
          constant: minimum password length.
private  java.util.HashMap<java.lang.String,User> userDB
          user database using HashMap.
 
Constructor Summary
UserDatabase()
           
 
Method Summary
 User createAccount(java.lang.String f, java.lang.String l, java.lang.String u, java.lang.String p)
          This method checks if the password contains the username, if the password length is less than the minPwdLength, if username is unique, and if any of these conditions is true, returns null.
 boolean isAvailable(java.lang.String u)
           
 User login(java.lang.String u, java.lang.String p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minPwdLength

public static final int minPwdLength
constant: minimum password length. Currently 6.

See Also:
Constant Field Values

userDB

private java.util.HashMap<java.lang.String,User> userDB
user database using HashMap.

Constructor Detail

UserDatabase

public UserDatabase()
Method Detail

createAccount

public User createAccount(java.lang.String f,
                          java.lang.String l,
                          java.lang.String u,
                          java.lang.String p)
This method checks if the password contains the username, if the password length is less than the minPwdLength, if username is unique, and if any of these conditions is true, returns null. If the provided parameters pass all these checks, this method creates a new User objects with the provided parameters, adds it to the user database, and returns the newly created User object.

Parameters:
f - first name
l - last name
u - username
p - password
Returns:
User object created with the parameter, if successful. Otherwise null

login

public User login(java.lang.String u,
                  java.lang.String p)
Parameters:
u - username
p - password
Returns:
If the user exists in the database and the password matches, then return the User object. Otherwise null.

isAvailable

public boolean isAvailable(java.lang.String u)
Parameters:
u -
Returns:
true if this username is available, false otherwise.