package databases;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import maps.Location;

/**
 * @author   Giorgio Ravera
 */
public class DatabaseLuoghi
{
	protected static DatabaseLuoghi theInstance;
	
	private Map<String, List<Location>> map = new LinkedHashMap<String, List<Location>>();

	private DatabaseLuoghi() { super(); }
	
	public static DatabaseLuoghi getInstance()
	{
		if (theInstance == null)
		{	
			theInstance = new DatabaseLuoghi();
		}
		return theInstance;
	}
	
	public void put(String s, List<Location> l)
	{
		map.put(s, l);
	}
	
	public List<Location> get(String s)
	{
		List<Location> l = map.get(s);
		if(l==null)
		{
			l = new LinkedList<Location>();
			map.put(s, l);
			return l;
		}
		Collections.sort(l);
		return l;
	}
	
	public void printList(String c)
	{
		List<Location> distanze = this.get(c);
		Iterator<Location> i = distanze.iterator();
		while(i.hasNext())
			System.out.println(i.next());
	}
	
	public Iterator<Location> getIterator(String c)
	{
		List<Location> distanze = this.get(c);
		return distanze.iterator();
	}
	
}
