import java.util.ArrayList; import java.util.Map; import java.util.TreeMap; /** * Created by leon on 1/23/18. */ public class PhoneBook { public static void main (String[] args){ } private Map> directory; public PhoneBook (){ directory= new TreeMap< String, ArrayList>(); } public void setValues(String name, ArrayListphonenumber){ this.directory.put(name, phonenumber); } public boolean hasEntry(String name) { return directory.containsKey(name); } public void add(String name, String number) { ArrayList contact = new ArrayList<>(); contact.add(number); directory.put(name,contact); } public ArrayList getContact(String name) { return directory.get(name); } public String reverseLookUp(String number){ String repply= "Not here"; for (String name:directory.keySet()){ ArrayList reverse= directory.get(name); for (String looking: reverse){ if (looking.equals(number)){ repply= name; } } } return repply; } public void remove (String name){ if (directory.containsKey(name)){ directory.remove(name); } } public String listNameAndNumbers() { StringBuilder builder = new StringBuilder(); for (String name:directory.keySet()){ for (int i= 0; i< directory.get(name).size(); i++){ builder.append(name + " " + directory.get(name).get(i) + "\n"); } } return builder.toString(); } public Map> getDirectory() { return directory; } public Map> getContact() { return directory; } public void setDirectory(Map> directory) { this.directory = directory; } }