Package org.example.customer

# Class OrderItem

java.lang.Object
org.example.customer.utility.CustomerEntity
org.example.customer.OrderItem

All Implemented Interfaces:
  `Serializable`

public final class OrderItem extends CustomerEntity implements 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:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `OrderItem()`
  The default constructor for the OrderItem class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  The equals() method of the OrderItem class.
  `int`
  `getOrderId()`
  Returns the orderId value for the Order.
  `int`
  `getProductId()`
  Returns the productId value for the OrderItem.
  `int`
  `getQuantity()`
  Returns the Quantity value for the OrderItem.
  `double`
  `getSubTotal()`
  Returns the SubTotal value for the OrderItem.
  `double`
  `getUnitPrice()`
  Returns the UnitPrice value for the OrderItem.
  `int`
  `hashCode()`
  The hashCode() method of the OrderItem class.
  `void`
  `setOrderId(int orderId)`
  Sets the orderId value for the OrderItem.
  `void`
  `setProductId(int productId)`
  Sets the productId value for the Order.
  `void`
  `setQuantity(int quantity)`
  Sets the Quantity value for the OrderItem.
  `void`
  `setUnitPrice(double unitPrice)`
  Sets the UnitPrice value for the OrderItem.
  `String`
  `toString()`
  The toString method for the OrderItem 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

  - ### 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
    This will also recompute the subTotal value.
    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
    This will also recompute the subTotal value.
    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:
      `hashCode` in class `CustomerEntity`
    Returns:
      the hashCode value for this Order object
    See Also:
      - `Object.hashCode()`

  - ### equals

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

    This method uses:

    - id
    - order id
    - product id
    - unit price
    - quantity
    Overrides:
      `equals` in class `CustomerEntity`
    Parameters:
      `obj` - the incoming object to compare against
    Returns:
      true if the fields being compared are equal
    See Also:
      - `Object.equals(Object obj)`

  - ### toString

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