/**
 * Copyright (c) 2005 Red Hat, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * Component of: Red Hat Application Server
 *
 * Initial Developers: Gregory Lapouchnian
 *                     Patrick Smith
 * --------------------------------------------------------------------------
 * $Id$
 * --------------------------------------------------------------------------
 */
package olstore.client;

import java.text.DecimalFormat;

/**
 * Represents an order for an item.
 */
public class OrderItem extends Item {

    /** The quantity being ordered for this item. */
    private int quantity;

    /**
     * Create a new order for a given item.
     * @param item the item being ordered
     */
    public OrderItem(Item item) {
        super(item.getTitle(), item.getDescription(), item.getPrice(), item
                .getCategory(), item.getId(), item.getImage());

        quantity = 1;
    }

    /**
     * Get the quantity being ordered.
     * @return Returns the quantity.
     */
    public int getQuantity() {
        return quantity;
    }

    /**
     * Set the quantity for this item.
     * @param quantity The quantity to set.
     */
    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object other) {
        return getId().equals(((OrderItem) other).getId());
    }

    /**
     * Get the total for this order.
     * @return the total price for this order
     */
    public double getTotal() {
        DecimalFormat formatter = new DecimalFormat("#.00");
        return (double) quantity
                * Double.valueOf(super.getPrice()).doubleValue();
    }
}
