-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How do you implement the equals method in a tree?
PostPosted: Wed Sep 10, 2003 3:51 pm 
Newbie

Joined: Fri Sep 05, 2003 1:58 pm
Posts: 2
Location: Atlanta, GA
Let's say you have classes in a tree like below: (the getters and setters have been omitted.)

Code:
class Country {
  String code;
  Set provinces;  // of type Province
}

class Province {
  String code;
  Set cities; // of type City
}

class City {
  String code;
}


Seems like a simple tree. If I were writing this data model just for Java then my equals and hasCode methods would traverse the children when computing equality. The Country.equals() method would compare codes then ensure that they contain the same number of provinces then call the equals method on all it's provinces. The Province.equals() method would ensure the codes are equal then check the number of cities then call the equals method on all of it's cities. The City.equals() method would be atomic and only check that the codes are equal.

Would there be any issues with doing this when the tree is loaded/stored using Hibernate? Should I just be checking primary keys (which might break the equals method contract)?

Thanks,
-alan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2003 10:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.