Package org.example.customer
Class Order
java.lang.Object
org.example.customer.utility.CustomerEntity
org.example.customer.Order
- All Implemented Interfaces:
Serializable,Comparable<Order>
The Order Entity for the Customer application.
This class represents the following DB Table:
This class represents the following DB Table:
CREATE TABLE ORDERS (
ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
ORDER_DATE DATE NOT NULL,
CUSTOMER_ID INTEGER,
TOTAL_AMOUNT DECIMAL(12,2),
ORDER_NUMBER VARCHAR(10),
CONSTRAINT PK_ORDER PRIMARY KEY (ID)
);
- Version:
- 1.0
- Author:
- Jonathan Earl
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintThis will enable sorting of Order by Order number concatenated with Order Date.booleanThe equals() method of the order class.intReturns the id value for the Customer Id.Returns the orderDate value for the Order.Returns the orderItem list value for the Order.Returns the orderNumber value for the Order.doubleReturns the total amount for the order.inthashCode()The hashCode() method of the Order class.voidsetCustomerId(int customerId) Sets the id value for the Customer ID.voidsetOrderDate(LocalDate orderDate) Sets the order date value for the Customer.voidsetOrderItems(List<OrderItem> orderItems) Sets the orderItem list value for the Order.voidsetOrderNumber(String orderNumber) Sets the orderNumber value for the Order.voidsetTotalAmount(double totalAmount) Sets the total amount value for the Orde.toString()The toString method for the Order class.Methods inherited from class org.example.customer.utility.CustomerEntity
getId, setId
-
Constructor Details
-
Order
public Order()The default constructor for the Order class.
The initial values are:- id: 1
- orderDate: Current Date
- customerId: 1
- totalAmount: 0.00
- orderNumber: null
- orderItems: empty
-
Order
public Order(org.example.websecurity.XssSanitizer sanitizer) The overloaded constructor for the order class that takes an XssSanitizer as input.The initial values are:
- id: 1
- orderDate: Current Date
- customerId: 1
- totalAmount: 0.00
- orderNumber: null
- orderItems: empty
- Parameters:
sanitizer- the XssSanitizer used by this instance
-
-
Method Details
-
compareTo
This will enable sorting of Order by Order number concatenated with Order Date.
- Specified by:
compareToin interfaceComparable<Order>- Parameters:
other- the Order object to compare with- Returns:
- the sort value of negative/zero/positive
-
getOrderDate
Returns the orderDate value for the Order.- Returns:
- the orderDate value for the order
-
setOrderDate
Sets the order date value for the Customer.The business rules are:
- the order date must not be null
- the order date must today or earlier
- Parameters:
orderDate- the value to set into the orderDate field- Throws:
IllegalArgumentException- if the first name is invalid
-
getCustomerId
public int getCustomerId()Returns the id value for the Customer Id.- Returns:
- the id value for the customer id
-
setCustomerId
public void setCustomerId(int customerId) Sets the id value for the Customer ID.The business rules are:
- the id must be 1 or greater
- Parameters:
customerId- the value to set into the customer id field- Throws:
IllegalArgumentException- if the customerId is invalid
-
getTotalAmount
public double getTotalAmount()Returns the total amount for the order.- Returns:
- the totalAmount value for the order
-
setTotalAmount
public void setTotalAmount(double totalAmount) Sets the total amount value for the Orde.The business rules are:
- the TotalAmount must be 0.01 or greater
- Parameters:
totalAmount- the value to set into the totalAmount field- Throws:
IllegalArgumentException- if the totalAmount is invalid
-
getOrderNumber
Returns the orderNumber value for the Order.- Returns:
- the orderNumber value for the order
-
setOrderNumber
Sets the orderNumber value for the Order.The business rules are:
- the orderNumber may be null
- the orderNumber must not be empty
- the orderNumber must min length of 2 chars
- the orderNumber must max length of 10 chars
- XSS strings within the orderNumber will be removed
- Parameters:
orderNumber- the value to set into the Order Number field- Throws:
IllegalArgumentException- if the orderNumber is invalid
-
getOrderItems
Returns the orderItem list value for the Order.- Returns:
- the myOrderItems for the order
-
setOrderItems
Sets the orderItem list value for the Order.The business rules are:
- the orderItems must not be null
- the orderItems may be empty
- Parameters:
orderItems- the list to set into the orderItems- Throws:
IllegalArgumentException- if the orderItems is invalid
-
hashCode
public int hashCode()The hashCode() method of the Order class.This method uses:
- id
- order date
- customer id
- order number
- Overrides:
hashCodein classCustomerEntity- Returns:
- the hashCode value for this Order object
- See Also:
-
equals
The equals() method of the order class.This method uses:
- id
- order date
- customer id
- order number
- 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 Order class. this method will return:
Order [Id=xxx, OrderDate=xx/xx/xx, CustomerId=xxx, TotalAmount=xxx, OrderNumber=xxx]- Overrides:
toStringin classCustomerEntity
-