import java.util.*;

/**
 * A factory that creates DirectoryListing objects
 *
 * This class is part of an example that illustrates the use of
 * the FactoryMethod pattern.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class DirectoryListingFactory
{
    private Map<String,DirectoryListing>   pool;


    /**
     * Default Constructor
     */
    public DirectoryListingFactory()
    {
       pool = new HashMap<String,DirectoryListing>();
    }


    /**
     * Create a DirectoryListing object
     *
     * Because DirectoryListing objects are expensive to create,
     * this method may return an existing DirectoryListing object
     * if one exists
     *
     * @param path    The path to the directory
     * @return        The DirectoryListing
     */
    public DirectoryListing createDirectoryListing(String path)
    {
       DirectoryListing       dl;

       dl = pool.get(path);
       if (dl == null) 
       {
          dl = new DirectoryListing(path);
          pool.put(path, dl);
       }
	
       return dl;
    }

}
