public class Cart extends Object implements Streamable<CartItem>, Priced
Constructor and Description |
---|
Cart() |
Modifier and Type | Method and Description |
---|---|
void |
addItemsTo(Order order)
Turns the current state of the cart into an
Order . |
CartItem |
addOrUpdateItem(Product product,
double amount)
|
CartItem |
addOrUpdateItem(Product product,
long amount)
|
CartItem |
addOrUpdateItem(Product product,
Quantity quantity)
|
void |
clear()
Clears the cart.
|
Optional<CartItem> |
getItem(String identifier)
Returns the CartItem for the given identifier.
|
javax.money.MonetaryAmount |
getPrice()
Returns the price of the item.
|
boolean |
isEmpty()
Returns whether the
Cart is currently empty. |
Iterator<CartItem> |
iterator() |
Optional<CartItem> |
removeItem(String identifier)
Removes the
CartItem with the given identifier. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
empty, of, ofLazy, stream
forEach, spliterator
public CartItem addOrUpdateItem(Product product, Quantity quantity)
CartItem
for the given Product
and Quantity
. If a CartItem
for the given
Product
already exists the Cart
will be updated to reflect the combined Quantity
for the
backing CartItem
.product
- must not be nullquantity
- must not be nullCartItem
.public CartItem addOrUpdateItem(Product product, long amount)
CartItem
for the given Product
and amount. If a CartItem
for the given
Product
already exists the Cart
will be updated to reflect the combined Quantity
for the
backing CartItem
.product
- must not be null.amount
- must not be null.public CartItem addOrUpdateItem(Product product, double amount)
CartItem
for the given Product
and amount. If a CartItem
for the given
Product
already exists the Cart
will be updated to reflect the combined Quantity
for the
backing CartItem
.product
- must not be null.amount
- must not be null.public Optional<CartItem> removeItem(String identifier)
CartItem
with the given identifier.identifier
- must not be null.public Optional<CartItem> getItem(String identifier)
identifier
- must not be null.public void clear()
public boolean isEmpty()
Cart
is currently empty.public void addItemsTo(Order order)
Order
.order
- must not be null.IllegalStateException
- if the given Order is not OrderStatus.OPEN
anymore.public javax.money.MonetaryAmount getPrice()
Priced
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.