Package openbook.domain
Class ShoppingCart
- java.lang.Object
-
- openbook.domain.ShoppingCart
-
- All Implemented Interfaces:
java.io.Serializable
public class ShoppingCart extends java.lang.Object implements java.io.Serializable
A non-persistent entity holds the content of a shopping session for a Customer. Used to create a persistent PurchaseOrder. Books can be added or removed from this cart.- Author:
- Pinaki Poddar
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addItem(Book book, int quantity)
Add the given book with the given quantity in the cart.void
changeQuantity(Book book, int delta)
Change the quantity of the given book by the given delta.void
clear()
Customer
getCustomer()
Gets the Customer who owns this cart.java.util.Map<Book,java.lang.Integer>
getItems()
Gets the books with their corresponding quantity in this cart.int
getTotalCount()
boolean
isEmpty()
void
remove(Book book)
Removes the given book from this cart.
-
-
-
Method Detail
-
getCustomer
public Customer getCustomer()
Gets the Customer who owns this cart.- Returns:
- non-null Customer.
-
getItems
public java.util.Map<Book,java.lang.Integer> getItems()
Gets the books with their corresponding quantity in this cart.
-
addItem
public void addItem(Book book, int quantity)
Add the given book with the given quantity in the cart. If the book already exists then the quantity is added to the existing quantity.- Parameters:
book
- non-null Bookquantity
- a positive quantity.
-
changeQuantity
public void changeQuantity(Book book, int delta)
Change the quantity of the given book by the given delta.- Parameters:
book
- a non-null Book that must exist in this cart.delta
- no. of quantity to change. Can be positive or negative. If the resultant quantity becomes zero of negative, the book is removed from the cart.
-
remove
public void remove(Book book)
Removes the given book from this cart.- Parameters:
book
- book a non-null Book that must exist in this cart.
-
clear
public void clear()
-
isEmpty
public boolean isEmpty()
-
getTotalCount
public int getTotalCount()
-
-