I have a method that seems to be too much for one method. I might be validating programming methodology. I just don't know what to do with it. Would a switch statement be better? Should I break it up and provide other methods?
public void addToCart(OrderlineType orderline) throws Exception
{
if (orderline == null)
{
throw new OutOfStockException("Null object pass addToCart");
}
if(orderline.getProduct().isRecallStatus())
{
throw new ProductRecallException("Product Id: " + orderline.getProduct().getProductId()
+ " is being Recalled");
}
int tempOrderlineQuantity = orderline.getQuantity();
int tempOrderlineProductId = orderline.getProduct().getProductId();
if( Inventory.getInstance().getQuantity(tempOrderlineProductId)
== tempOrderlineQuantity )
{
shoppingCart.add(orderline);
log.warn("Product " + orderline.getProduct().getProductName()
+" ID: "+ tempOrderlineProductId
+ "after purchase will have no more in stock");
}
else if(Inventory.getInstance().getQuantity(tempOrderlineProductId)
> tempOrderlineQuantity)
{
shoppingCart.add(orderline);
}
else if(Inventory.getInstance().getQuantity(tempOrderlineProductId)
== -1)
{
throw new OutOfStockException("PrductId: " + tempOrderlineProductId
+ " is not listed in the Inventory: "
+ Inventory.getInstance().getQuantity(tempOrderlineProductId));
}
else
{
throw new OutOfStockException("PrductId: " + tempOrderlineProductId
+ " does not have enough to complete this order, the in Stock amount is: "
+ Inventory.getInstance().getQuantity(tempOrderlineProductId));
}
}