FileDocCategorySizeDatePackage
PurchaseOrder.javaAPI DocExample2268Fri Mar 01 11:27:30 GMT 2002javajaxb.po

PurchaseOrder.java

package javajaxb.po;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 *  The <code>PurchaseOrder</code> class represents a complete PO within
 *    an application.
 * </p>
 */
public class PurchaseOrder {

    /** The list of <code>{@link Order}</code> objects */
    protected List orderList;

    /**
     * <p>
     *  Initialize storage.
     * </p>
     */
    public PurchaseOrder() {
        this(new LinkedList());
    }
    
    /**
     * <p>
     *  This will create the PO with a predefined list of
     *    <code>{@link Order}</code> objects.
     * </p>
     *
     * @param orderList the list of orders.
     */
    public PurchaseOrder(List orderList) {
        if (orderList != null) {
            this.orderList = orderList;
        } else {
            this.orderList = new LinkedList();
        }
    }

    /**
     * <p>
     *  This will return the current list of orders.
     * </p>
     *
     * @return <code>List</code> - list of orders.
     */
    public List getOrderList() {
        return orderList;
    }

    /**
     * <p>
     *  This will set the list of orders. It also replaces any
     *    existing orders with the supplied list.
     * </p>
     *
     * @param orderList list of orders.
     */
    public void setOrderList(List orderList) {
        this.orderList = orderList;
    }

    /**
     * <p>
     *  This will add a new <code>{@link Order}</code>
     *    to this PO.
     * </p>
     *
     * @param order the new <code>Order</code> to add.
     */
    public void addOrder(Order order) {
        orderList.add(order);
    }

    /**
     * <p>
     *  This will calculate the total cost for this PO
     * </p>
     *
     * @return <code>float</code> - the total price for this PO
     */
    public float getTotalPrice() {
        if (orderList == null) {
            return 0;
        }
        
        float totalPrice = 0;
        for (Iterator i = orderList.iterator(); i.hasNext(); ) {
            Order order = (Order)i.next();
            totalPrice += order.getStock().getQuantity() * order.getPurchasePrice();
        }
        return totalPrice;
    }
}