• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S :Equals and Hashcode

 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt regarding the implementation of equals and hashcode methods.In some previous posts it has been said that we could compare them with record numbers.

1.Is there any possiblity that the record Number is different or might not exist.I could not think of such situation.If it is so please convey it to me.

Some have suggested by combining both the contractor name and City.I have a doubt for this.Why not two contractors having the same name could live in a same city.If so how should we know the uniqueness of a record be checked.

2.Is the verification based on the record number alone is okay or is any other idea is better

Thanks for your time
 
Kevin Florish
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is one of many grey areas in the spec that is open to intepretation.

Having looked through the entire data file (all be it a small file) I made the decision that the name/location fields do make up a unique search criteria.

It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.


How else could the user get a duplicate record?

Of course this is my interpretation of the spec and I will document this in my decisions document.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you are of course correct.This is one of the grey areas where it is open to interpretation.It has been given that

It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user.
.
That is for a search crieteria(In my opinion).However for the uniqueness of the record i am in doubt regarding this single point

Why not two contractors having the same name could live in a same city
.

Sorry Kevin for re-stating this.But please do clarify.I am in doubt or i could not understand

Thanks to kevin for his time .
 
Kevin Florish
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I am of the reasoning that if 2 contractors with same name are in same city, they are in fact the same as far as this assignment is concerned.

I even check thie name/location when doing a createRecord() so my design is logical with this decision.

For me this makes sense in the context of this assignment and I am intepreting the requirements with a KISS attitude

Cheers Kevin.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks kevin for your reply
 
Yemi Dalley
Greenhorn
Posts: 12
MyEclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important thing is to document such an assumption, KISS is okay but note that you implement hashcode and equals yourself.
The hashcode might not even use any of your properties.

 
Alain Dickson
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sree,
I am using recrod numbers i.e offsets form the start of file for search method and make Stirng comparision.
but I think I will need equals and hashcode for create method, if I don't leave the responsibility on the user not to create duplicate record.
And, It is possible(and ok to assume) to have two contractors with same name in a city, You can include "rate" and "number of people" fields into your hashcode and equals implimentation, THEN it will be very rare to have contractor with same name, in same city, with same rate, with same number of people working with the contractor.

Regards,
Alain
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Yemi Dalley Alain Dickson for your reply
 
Kevin Florish
Ranch Hand
Posts: 182
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic