Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equals & hashcode implementation in B&S

 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am working on B&S 2.2.3. I have a transfer object and I have implemented equals & hashcode methods are as follows



I verified the following properties of equals method
[bold] symmetry [/bold]
[bold] reflexivity [/bold]
[bold] transitivity [/bold]
[bold] consistency with hashcode [/bold]

the first three properties are returning true and same hashcode is returned if two objects are equal. For transitivity , I used three objects.

Do I need to consider anything else?
Is the above implementation correct?

post your comments

sat
 
Pete Palmer
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi satishkumar,

I am just staring on my B&S (2.2.2) assignement and can't answer your question,however, I was just curious as to what scenario do you need to compare two instances of the Contractor object ?

Pete
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pete,

I have a Transfer object which contains the complete data for a single record. In a standalone environment, the possibility of creating the same record is almost zero. But in distributed environment, there might be a chance of getting multiple copies of the same record. Each copy will be deserialized into separate instantiation of the Transfer Object class. So here I need to differentiate the two objects hence I have overridden the equals & hashcode methods.
The hashcode must be implemented correctly if the Transfer Object is used as key in hash based collections.

sat
 
Alain Dickson
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satishkumar, I think you are doing more than the requirements, there is no requirement for the GUI to have functionality to create a new record, so why do you need to carry the object to the server.

Alain
 
Ernesto Elias-Nieland
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satishkumar,

I am working on a different assignment, but I just use the record id for the equals method. This makes things realy easy.
However, in my assignment (URLyBird 1.3.2) two records are not equal if all data in the record is the same. I don't know if this is also the case for your data model, e.g. two contractors with the same name, location and speciality that are actually two different records in the db.

Cheers,
Ernesto
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all;

in my opinion; the record id is enough to uniqualy identify the contractor.

what you think guys ?

regards.
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you for posting your comments on this issue. Record ID is enough to identify the record provided the records position not changed in the db. If the records are added in the middle or deleted in the middle, we need to identify the record uniquely by concatenating name, location and speciality etc.

sat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic