I am creating a phone book API in Java. Every name in my phone book is mapped to a set of phone numbers & address. I want to build a search function which can search an entry in my phone book using a search parameter as a name or as the phone number itself.
My approach has been to add all my entries to a:
Map <String, PhoneNumber> book = new HashMap <String,PhoneNumber>();
book.put("Name1",new PhoneNumber(new Integer(12345),new Integer(123456));
book.get("Name1");
// PhoneNumber is my class which can have different types of phone numbers
I want to search by both the name which is the key and also by the value. I cannot do that using a HashMap. Is there a way to do it better to implement an efficient searching process?