Package org.example.customer
Class Customer
java.lang.Object
org.example.customer.utility.CustomerEntity
org.example.customer.Customer
- All Implemented Interfaces:
Serializable,Comparable<Customer>
The Customer Entity for the Customer application.
This class represents the following DB Table:
This class represents the following DB Table:
CREATE TABLE CUSTOMER (
ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
FIRST_NAME VARCHAR(40) NOT NULL,
LAST_NAME VARCHAR(40) NOT NULL,
CITY VARCHAR(40),
COUNTRY VARCHAR(40),
PHONE VARCHAR(20),
CONSTRAINT PK_CUSTOMER PRIMARY KEY (ID)
);
- Version:
- 1.0
- Author:
- Jonathan Earl
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintThis will enable sorting of Customers by full name.booleanThe equals() method of the Customer class.Returns the first name value for the Customer.Returns the last name value for the Customer.Return the Location for the Customer.getPhone()Returns the phone value for the Customer.inthashCode()The hashCode() method of the Customer class.voidsetFirstName(String firstName) Sets the first name value for the Customer.voidsetLastName(String lastName) Sets the last name value for the Customer.voidsetLocation(Location location) Sets the location value for the Customer.voidSets the phone value for the Customer.toString()The toString method for the Customer class.Methods inherited from class org.example.customer.utility.CustomerEntity
getId, setId
-
Constructor Details
-
Customer
public Customer()The default constructor for the Customer class.The initial values are:
- id: 1
- first name: John
- last name: Smith
- city: New York City
- country: United States of America
- phone: null
-
Customer
public Customer(org.example.websecurity.XssSanitizer sanitizer) The overloaded constructor for the Customer class that takes an XssSanitizer as input.The initial values are:
- id: 1
- first name: John
- last name: Smith
- city: New York City
- country: United States of America
- phone: null
- Parameters:
sanitizer- the XssSanitizer used by this instance
-
-
Method Details
-
compareTo
This will enable sorting of Customers by full name.
- Specified by:
compareToin interfaceComparable<Customer>- Parameters:
other- the Customer object to compare with- Returns:
- the sort value of negative/zero/positive
-
getFirstName
Returns the first name value for the Customer.- Returns:
- the first name value for the customer
-
setFirstName
Sets the first name value for the Customer.
The business rules are:- the first name must not be null
- the first name must not be empty
- the first name must max length of 40 chars
- XSS strings within the first name will be removed
- Parameters:
firstName- the value to set into the customer first name field- Throws:
IllegalArgumentException- if the first name is invalid
-
getLastName
Returns the last name value for the Customer.- Returns:
- the last name value for the customer
-
setLastName
Sets the last name value for the Customer.The business rules are:
- the last name must not be null
- the last name must not be empty
- the last name must min length of 2 chars
- the last name must max length of 40 chars
- XSS strings within the last name will be removed
- Parameters:
lastName- the value to set into the customer last name field- Throws:
IllegalArgumentException- if the last name is invalid
-
getLocation
Return the Location for the Customer.- Returns:
- the myLocation
-
setLocation
Sets the location value for the Customer.The business rules are:
- the location may be null
- Parameters:
location- the value to set into the customer location field- Throws:
IllegalArgumentException- if the location is invalid
-
getPhone
Returns the phone value for the Customer.- Returns:
- the phone value for the customer
-
setPhone
Sets the phone value for the Customer.The business rules are:
- the phone may be null
- Parameters:
phone- the value to set into the customer phone field- Throws:
IllegalArgumentException- if the phone is invalid
-
hashCode
public int hashCode()The hashCode() method of the Customer class.This method uses:
- id
- first name
- last name
- city
- country
- Overrides:
hashCodein classCustomerEntity- Returns:
- the hashCode value for this Customer object
- See Also:
-
equals
The equals() method of the Customer class.This method uses:
- id
- first name
- last name
- city
- country
- Overrides:
equalsin classCustomerEntity- Parameters:
obj- the incoming object to compare against- Returns:
- true if the fields being compared are equal
- See Also:
-
toString
The toString method for the Customer class. this method will return:
Customer [Id=xxx, FirstName=xxx, LastName=xxx, City=xxx, Country=xxx, Phone=xxx]- Overrides:
toStringin classCustomerEntity
-