Class Product

All Implemented Interfaces:
Serializable, Comparable<Product>

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

This class represents the following DB Table:

 CREATE TABLE PRODUCT (
      ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
      PRODUCT_NAME VARCHAR(50) NOT NULL,
      SUPPLIER_ID INTEGER NOT NULL,
      UNIT_PRICE DECIMAL(12,2),
      PACKAGE  VARCHAR(30),
      IS_DISCONTINUED BOOLEAN,
      CONSTRAINT PK_PRODUCT PRIMARY KEY (ID)
   );
 
Version:
1.0
Author:
Jonathan Earl
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default constructor for the Product class.
    Product(org.example.websecurity.XssSanitizer sanitizer)
    The overloaded constructor for the Product class that takes an XssSanitizer as input.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    This will enable sorting of Products by name.
    boolean
    The equals() method of the Product class.
    Returns the packaging value for the Product.
    Returns the product name value for the Product.
    int
    Returns the SupplierId value for the Product.
    double
    Returns the UnitPrice value for the Product.
    int
    The hashCode() method of the Product class.
    boolean
    Returns the Discontinued value for the Product.
    void
    setDiscontinued(boolean discontinued)
    Sets the Discontinued value for the Product.
    void
    setPackaging(String packaging)
    Sets the packaging value for the Product.
    void
    setProductName(String productName)
    Sets the product name value for the Product.
    void
    setSupplierId(int supplierId)
    Sets the SupplierId value for the Product.
    void
    setUnitPrice(double unitPrice)
    Sets the UnitPrice value for the Product.
    The toString method for the Product class.

    Methods inherited from class org.example.customer.utility.CustomerEntity

    getId, setId

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Product

      public Product()
      The default constructor for the Product class.

      The initial values are:

      • id: 1
      • product name: Paper Envelope
      • supplier id: 1
      • unit price: 0.01
      • packaging: single
      • discontinued: false
    • Product

      public Product(org.example.websecurity.XssSanitizer sanitizer)
      The overloaded constructor for the Product class that takes an XssSanitizer as input.

      The initial values are:

      • id: 1
      • product name: Paper Envelope
      • supplier id: 1
      • unit price: 0.01
      • packaging: single
      • discontinued: false
      Parameters:
      sanitizer - the XssSanitizer used by this instance
  • Method Details

    • compareTo

      public int compareTo(Product other)
      This will enable sorting of Products by name.

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

      public String getProductName()
      Returns the product name value for the Product.
      Returns:
      the product name value for the Product
    • setProductName

      public void setProductName(String productName)
      Sets the product name value for the Product.

      The business rules are:

      • the product name must not be null
      • the product name must not be empty
      • the product name must max length of 50 chars
      • XSS strings within the product name will be removed
      Parameters:
      productName - the value to set into the product name field
      Throws:
      IllegalArgumentException - if the product name is invalid
    • getSupplierId

      public int getSupplierId()
      Returns the SupplierId value for the Product.
      Returns:
      the supplierId value for the Product
    • setSupplierId

      public void setSupplierId(int supplierId)
      Sets the SupplierId value for the Product.

      The business rules are:

      • the SupplierId must be 1 or greater
      Parameters:
      supplierId - the value to set into the supplier id field
      Throws:
      IllegalArgumentException - if the id is invalid
    • getUnitPrice

      public double getUnitPrice()
      Returns the UnitPrice value for the Product.
      Returns:
      the UnitPrice value for the Product
    • setUnitPrice

      public void setUnitPrice(double unitPrice)
      Sets the UnitPrice value for the Product.

      The business rules are:

      • the UnitPrice must be 0.01 or greater
      Parameters:
      unitPrice - the value to set into the unitPrice field
      Throws:
      IllegalArgumentException - if the UnitPrice is invalid
    • getPackaging

      public String getPackaging()
      Returns the packaging value for the Product.
      Returns:
      the packaging value for the Product
    • setPackaging

      public void setPackaging(String packaging)
      Sets the packaging value for the Product.

      The business rules are:

      • the packaging may be null
      • the packaging must not be empty
      • the packaging must min length of 2 chars
      • the packaging must max length of 30 chars
      • XSS strings within the packaging will be removed
      Parameters:
      packaging - the value to set into the Product packaging field
      Throws:
      IllegalArgumentException - if the packaging is invalid
    • isDiscontinued

      public boolean isDiscontinued()
      Returns the Discontinued value for the Product.
      Returns:
      the discontinued value for the Product
    • setDiscontinued

      public void setDiscontinued(boolean discontinued)
      Sets the Discontinued value for the Product.
      Parameters:
      discontinued - the value to set field
    • hashCode

      public int hashCode()
      The hashCode() method of the Product class.

      This method uses:

      • id
      • product name
      • supplier id
      • unit price
      • packaging
      Overrides:
      hashCode in class CustomerEntity
      Returns:
      the hashCode value for this Product object
      See Also:
    • equals

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

      This method uses:

      • id
      • product name
      • supplier id
      • unit price
      • packaging
      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 Product class. this method will return:
      Product [myId=xxx, myProductName=xxx, mySupplierId=xxx, myUnitPrice=xxx, myPackaging=xxx, myDiscontinued=xxx]
      Overrides:
      toString in class CustomerEntity