/*
 * Created on Sep 5, 2005
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package edu.uprm.ece.icom5016.bean;

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

/**
 * @author elliot
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class ShoppingCart {
	//private LinkedList cart = new LinkedList();
	private HashMap theCart = new HashMap();
	
	public ShoppingCart(){
		
	}
	
	public synchronized void addItem(ItemOrdered o){
		//cart.add(o);
		theCart.put(o.getItem().getId(), o);
	}
	
	public synchronized Collection getItems(){
		return theCart.values();
	}
	
	public synchronized Object getItem(String id){
		return theCart.get(id);
	}
	/**
	 * 
	 * @param id
	 * @return
	 */
	public synchronized boolean itemExists(String id){
		return theCart.containsKey(id);
	}
	
	public synchronized boolean hasItems(){
		return !theCart.isEmpty();
	}
	
	public synchronized void removeItem(String id){
		this.theCart.remove(id);
	}
	

}
