/*******************************************************************************
 * Copyright (c), 2001, 2002 N2 Broadband, Inc.  All Rights Reserved.
 *
 * This module contains unpublished, confidential, proprietary
 * material.  The use and dissemination of this material are
 * governed by a license.  The above copyright notice does not
 * evidence any actual or intended publication of this material.
 *
 * Author:  Drake H. Henderson
 * Created:  11-12-01
 *
 ******************************************************************************/
package com.n2bb.user;

import com.n2bb.util.N2bbSettings;

/**
 * Holds values for users of the webapp.
 *
 * @author dhenderson
 * @author kmatsuoka
 * @version $Id: UserBean.java,v 1.4 2007/06/20 22:22:16 vjakobac Exp $
 */
public class UserBean {

  private String userName = null;
  private String password = null;
  private String firstName = null;
  private String lastName = null;
  private String roleName = null;
  private String email = null;
  private String phone = null;
  private String status = null;
  private String extn = null;
  private String employeeId = null;
  private String department = null;
  private String location = null;
  
  private static final int HASHCODE_MULTIPLICATION_FACTOR = 31;

  private static final int HASHCODE_ADDITION_FACTOR = 97;
  
  private static final String DEFAULT_USER_NAME=null;
    /**
     * Checks if this user is the special N2BB Admin User.
     *
     * @return true if this user is the special N2BB Admin User
     */
    public boolean isAdminUser() {
        return userName != null &&
                userName.equalsIgnoreCase(N2bbSettings.ADMIN_USER);
    }

  public String getUserName() {
    return userName == null ? "" : userName;
  }

  public String getPassword() {
    return password == null ? "" : password;
  }

  public String getFirstName() {
    return firstName == null ? "" : firstName;
  }

  public String getLastName() {
    return lastName == null ? "" : lastName;
  }

  public String getRoleName() {
    return roleName == null ? "" : roleName;
  }

  public String getEmail() {
    return email == null ? "" : email;
  }

  public String getPhone() {
    return phone == null ? "" : phone;
  }

  public String getStatus() {
    return status == null ? "" : status;
  }

  public void setUserName(String userName) {
    this.userName = userName;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  public void setRoleName(String roleName) {
    this.roleName = roleName;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }

  public void setStatus(String status) {
    this.status = status;
  }
  public String getDepartment() {
		return department == null ? "" :department.trim();
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public String getEmployeeId() {
		return employeeId == null ? "" : employeeId.trim();
	}

	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}

	public String getExtn() {
		return extn == null ? "" : extn.trim();
	}

	public void setExtn(String extn) {
		this.extn = extn;
	}

	public String getLocation() {
		return location == null ? "" : location.trim();
	}

	public void setLocation(String location) {
		this.location = location;
	}
	@Override
	public boolean equals(Object obj)
	{
		if (obj instanceof UserBean)
		{
			UserBean resObj = (UserBean) obj;

			if (resObj.getUserName() != DEFAULT_USER_NAME && this.getUserName() != DEFAULT_USER_NAME)
			{
				return (resObj.getUserName().equals(this.getUserName()));
			}
			else
			{
				return super.equals(obj);
			}
		}

		return false;
	}

	/**
	 * Returns the Hashcode for this object
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		long hash = HASHCODE_MULTIPLICATION_FACTOR + HASHCODE_ADDITION_FACTOR;
		int hashCode = new Long(hash).hashCode();

		if (this.userName.equals(DEFAULT_USER_NAME))
		{
			hashCode = super.hashCode();
		}

		return hashCode;
	}

}


