Class Customer

All Implemented Interfaces:
Serializable, Comparable<Customer>

public final class Customer extends CustomerEntity implements Serializable, Comparable<Customer>
The Customer Entity for the Customer application.

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 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

      public int compareTo(Customer other)
      This will enable sorting of Customers by full name.

      Specified by:
      compareTo in interface Comparable<Customer>
      Parameters:
      other - the Customer object to compare with
      Returns:
      the sort value of negative/zero/positive
    • getFirstName

      public String getFirstName()
      Returns the first name value for the Customer.
      Returns:
      the first name value for the customer
    • setFirstName

      public void setFirstName(String firstName)
      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

      public String getLastName()
      Returns the last name value for the Customer.
      Returns:
      the last name value for the customer
    • setLastName

      public void setLastName(String lastName)
      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

      public Location getLocation()
      Return the Location for the Customer.

      Returns:
      the myLocation
    • setLocation

      public void setLocation(Location location)
      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

      public Phone getPhone()
      Returns the phone value for the Customer.
      Returns:
      the phone value for the customer
    • setPhone

      public void setPhone(Phone phone)
      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:
      hashCode in class CustomerEntity
      Returns:
      the hashCode value for this Customer object
      See Also:
    • equals

      public boolean equals(Object obj)
      The equals() method of the Customer class.

      This method uses:

      • id
      • first name
      • last name
      • city
      • country
      Overrides:
      equals in class CustomerEntity
      Parameters:
      obj - the incoming object to compare against
      Returns:
      true if the fields being compared are equal
      See Also:
    • toString

      public String 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:
      toString in class CustomerEntity