import java.awt.*;
import java.util.*;

/**
 * Using LinkedList
 * 
 * 1) Show the basics
 * 2) Find the "Gala" apple
 * 3) Make two lists, using remove and add
 * 
 * @author McKinley
 * @version April 2007
 */
public class Inventory
{

    public static void main (String [] args)
    {   
        // LinkedList Version of printing apples
        LinkedList<Items> apples = new LinkedList<Items>();
        Items a = new Items ("Ruby Red", 109);
        apples.add(a);
        a = new Items ("McIntosh", 8);
        apples.add(a);
        a = new Items ("Gala", 88);
        apples.addFirst(a);
        a = new Items ("Fuji", 40);
        apples.addLast(a);
        
        Iterator<Items> i = apples.iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }
        
        // Code:  Find number of ÒGalaÓ apples
        Iterator<Items> j = apples.iterator();
        while (j.hasNext()) {
            Items item = j.next(); 
            if (item.getName().equals("Gala")) {
                System.out.println("Gala has " + item.getAmount());
                // assuming only one Gala entry
                break;
            }
        }

        // Code: make two lists, apples with inventories < 50 and bigInv with
        //       inventories > 50

        LinkedList<Items> bigInv = new LinkedList<Items>();
        
        i = apples.iterator();
        while (i.hasNext()) {
            Items item = i.next();
            if (item.getAmount() > 50) {
                bigInv.add(item);
                i.remove();        // Note!!  you must call remove on the iterator
            }
            
        }
        
        
        System.out.println("\nLittle Inventory");        
        i = apples.iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }
  
        System.out.println("\nBig Inventory");        
        i = bigInv.iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }   
       
    }
}
