Package org.example.customer
Class Product
java.lang.Object
org.example.customer.utility.CustomerEntity
org.example.customer.Product
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionintThis will enable sorting of Products by name.booleanThe equals() method of the Product class.Returns the packaging value for the Product.Returns the product name value for the Product.intReturns the SupplierId value for the Product.doubleReturns the UnitPrice value for the Product.inthashCode()The hashCode() method of the Product class.booleanReturns the Discontinued value for the Product.voidsetDiscontinued(boolean discontinued) Sets the Discontinued value for the Product.voidsetPackaging(String packaging) Sets the packaging value for the Product.voidsetProductName(String productName) Sets the product name value for the Product.voidsetSupplierId(int supplierId) Sets the SupplierId value for the Product.voidsetUnitPrice(double unitPrice) Sets the UnitPrice value for the Product.toString()The toString method for the Product class.Methods inherited from class org.example.customer.utility.CustomerEntity
getId, setId
-
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
This will enable sorting of Products by name.
- Specified by:
compareToin interfaceComparable<Product>- Parameters:
other- the Product object to compare with- Returns:
- the sort value of negative/zero/positive
-
getProductName
Returns the product name value for the Product.- Returns:
- the product name value for the Product
-
setProductName
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
Returns the packaging value for the Product.- Returns:
- the packaging value for the Product
-
setPackaging
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:
hashCodein classCustomerEntity- Returns:
- the hashCode value for this Product object
- See Also:
-
equals
The equals() method of the Product class.This method uses:
- id
- product name
- supplier id
- unit price
- packaging
- 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 Product class. this method will return:
Product [myId=xxx, myProductName=xxx, mySupplierId=xxx, myUnitPrice=xxx, myPackaging=xxx, myDiscontinued=xxx]- Overrides:
toStringin classCustomerEntity
-