package simulator;

import java.util.Collection;

/*
 * ClosestRideFirst.java
 * Created on Jan 28, 2005
 *
 */

/**
 *  ClosestRideFirst - This class implements a customer that always picks the
 *  ride on the wish list thats closest to them (re-orders the list
 *  based on the distance away from the customer's current location).
 *  
 *  @author Ping
 *
 */
public class ClosestRideFirst extends Customer
{
    public static String CUSTOMER_TYPE = "Closest Ride First";
    
    /**
     * 
     * @param name
     * @param wishList
     * @param exitStrategy
     * @param timeEntered
     * @param desiredExitTime
     * @param logger
     */
    public ClosestRideFirst(String name, 
            Collection<PrioritizedElement<String, Integer>> wishList, 
            ExitStrategy exitStrategy, 
            Time timeEntered, 
            Time desiredExitTime)
    {    	
        super(name, wishList, exitStrategy, timeEntered, 
                desiredExitTime);
    }
    
    /**
     * This function will re-order the wish list based on the distance to
     * each ride within the wish list.
     */
    protected void selectRide()
    {
        super.selectRide();
        MyPriorityQueue<Attraction, Integer> newWishList = 
            new MyPriorityQueue<Attraction, Integer>();
        
        while(!agenda.isEmpty())
        {
            Attraction ride = agenda.dequeue();
            // enqueue the ride again based on the new distance
            newWishList.enqueue(ride, 
                    currLocation.distance(ride.getEntrance()));
        }
        agenda = newWishList;
    }
}
