Package org.example.customer
Class OrderItem
java.lang.Object
org.example.customer.utility.CustomerEntity
org.example.customer.OrderItem
- All Implemented Interfaces:
Serializable
The OrderItem Entity for the Customer application.
This class represents the following DB Table:
CREATE TABLE ORDER_ITEM (
ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
ORDER_ID INTEGER NOT NULL,
PRODUCT_ID INTEGER NOT NULL,
UNIT_PRICE DECIMAL(12,2) NOT NULL,
QUANTITY INTEGER NOT NULL,
CONSTRAINT PK_ORDERITEM PRIMARY KEY (ID)
);
- Version:
- 1.0
- Author:
- Jonathan Earl
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanThe equals() method of the OrderItem class.intReturns the orderId value for the Order.intReturns the productId value for the OrderItem.intReturns the Quantity value for the OrderItem.doubleReturns the SubTotal value for the OrderItem.doubleReturns the UnitPrice value for the OrderItem.inthashCode()The hashCode() method of the OrderItem class.voidsetOrderId(int orderId) Sets the orderId value for the OrderItem.voidsetProductId(int productId) Sets the productId value for the Order.voidsetQuantity(int quantity) Sets the Quantity value for the OrderItem.voidsetUnitPrice(double unitPrice) Sets the UnitPrice value for the OrderItem.toString()The toString method for the OrderItem class.Methods inherited from class org.example.customer.utility.CustomerEntity
getId, setId
-
Constructor Details
-
OrderItem
public OrderItem()The default constructor for the OrderItem class.The initial values are:
- id: 1
- orderId: 1
- productId: 1
- unitPrice: 0.01
- quantity: 1
- subTotal: unitPrice * quantity
-
-
Method Details
-
getOrderId
public int getOrderId()Returns the orderId value for the Order.- Returns:
- the orderId value for the order
-
setOrderId
public void setOrderId(int orderId) Sets the orderId value for the OrderItem.The business rules are:
- the orderId must be 1 or greater
- Parameters:
orderId- the value to set into the orderId field- Throws:
IllegalArgumentException- if the orderId is invalid
-
getProductId
public int getProductId()Returns the productId value for the OrderItem.- Returns:
- the productId value for the OrderItem
-
setProductId
public void setProductId(int productId) Sets the productId value for the Order.The business rules are:
- the productId must be 1 or greater
- Parameters:
productId- the value to set into the productId field- Throws:
IllegalArgumentException- if the productId is invalid
-
getUnitPrice
public double getUnitPrice()Returns the UnitPrice value for the OrderItem.- Returns:
- the UnitPrice value for the OrderItem
-
setUnitPrice
public void setUnitPrice(double unitPrice) Sets the UnitPrice value for the OrderItem.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
-
getQuantity
public int getQuantity()Returns the Quantity value for the OrderItem.- Returns:
- the Quantity value for the OrderItem
-
setQuantity
public void setQuantity(int quantity) Sets the Quantity value for the OrderItem.The business rules are:
- the Quantity must be 1 or greater
- Parameters:
quantity- the value to set into the Quantity field- Throws:
IllegalArgumentException- if the Quantity is invalid
-
getSubTotal
public double getSubTotal()Returns the SubTotal value for the OrderItem. The SunTotal will be recomputed any time the UnitPrice or Quantity changes.- Returns:
- the SubTotal value for the OrderItem
-
hashCode
public int hashCode()The hashCode() method of the OrderItem class.This method uses:
- id
- order id
- product id
- unit price
- quantity
- Overrides:
hashCodein classCustomerEntity- Returns:
- the hashCode value for this Order object
- See Also:
-
equals
The equals() method of the OrderItem class.This method uses:
- id
- order id
- product id
- unit price
- quantity
- 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 OrderItem class. this method will return:
OrderItem [Id=xxx", OrderId=xxx, ProductId=xxx, UnitPrice=xxx, Quantity=xxx, SubTotal=xxx]- Overrides:
toStringin classCustomerEntity
-