You can make them immutable and hide the constructor (make it
private), then provide a factory function

public createPerson(String firstName, String lastName, Date dob)

that internally maintains a hash of all Person's created so far and
never creates the same one twice. If you request the same more than
once, it returns the one already created.

Then collections can make comparisons based entirely on pointer values
rather than string and date comparisons.

On Dec 5, 1:48 am, DT <pa7...@gmail.com> wrote:
> Hi
>
> I have a Person Object that has members: firstname, lastname and DOB
> public class Person {
>     private String firstName;
>     private String lastName;
>     private Date dob;
>
>     /** Construct a Person given the first name, last name, and birth
> date. */
>     public Person(String firstName, String lastName, Date dob) {
>         if (firstName == null || lastName == null || dob == null) {
>             throw new IllegalArgumentException();
>         }
>         this.firstName = firstName;
>         this.lastName = lastName;
>         this.dob = dob;
>     }
>
> }
>
> The application uses Person objects in Collections, placing them into
> Collection implementations and querying if a Person is in a Collection
> using the Collection.contains() method. The application also uses
> Person objects as keys in Maps to associate other objects with Persons
> and to efficiently look up those objects based on Person.
> How can I modify this Person Object so that the lookup is efficient?
> Any help??

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to