package javakurs.musterloesung.uebung06;

/**
 * {@link FridgeCommand} implements the {@link Command} interface for
 * the fridge.
 *
 * @author Joerg Steffen, DFKI
 * @version $Id: FridgeCommand.java,v 1.1 2010/12/06 18:18:46 steffen Exp $
 */
public class FridgeCommand implements Command {

  /**
   * This contains the fridge on which this command works.
   */
  private AdvancedTableModelFridge fridge;

  /**
   * This contains the product whose amount is modified by this command.
   */
  private String product;

  /**
   * This contains the amount change of this command.
   */
  private double amount;


  /**
   * This creates a new instance of {@link FridgeCommand} for the given fridge,
   * product and amount.
   *
   * @param fridge
   *          the fridge
   * @param product
   *          the product
   * @param amount
   *          the amount
   */
  public FridgeCommand(
      AdvancedTableModelFridge fridge, String product, double amount) {

    this.fridge = fridge;
    this.product = product;
    this.amount = amount;
  }


  /**
   * {@inheritDoc}
   */
  @Override
  public void execute() {

   this.fridge.modifyStock(this.amount, this.product);
  }


  /**
   * {@inheritDoc}
   */
  @Override
  public void undo() {

    this.fridge.modifyStock(-1 * this.amount, this.product);
  }
}
