package carte;

import ville.Ville;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.LinkedList;

public class Table implements TableInterface<String>{
  private Map<Ville, Collection<String>> table;
  public Table() {
    table = new LinkedHashMap<Ville, Collection<String>>();
  }
  public boolean contient(Ville v) {
    return table.containsKey(v);
  }
  public int taille() {
    return table.size();
  }
  public Collection<Ville> sommets() {
    return table.keySet();
  }
  public void ajouterVille(Ville v) {
    if (! contient(v))
      table.put(v, new LinkedList<String>());
    else throw new IllegalArgumentException ("Ville deja presente");
  }
  public void ajouterVoisin(Ville v, String nom) {
    Collection<String> c = table.get(v);
    if (c == null)
      throw new IllegalArgumentException("Ville inconnue");
    c.add(nom);
  }
  public Collection<String> voisins(Ville s){
      Collection<String> c = table.get(s);
      if (c == null)
	  throw new IllegalArgumentException("Ville inconnue");
      return c;
  }
} 
