• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deleting complex object in Java list  RSS feed

 
Nenad Bulatovic
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am following those three tutorials and I have completed it with success.

( http://oracleadfhowto.blogspot.in/2013/03/create-simple-web-service-using-oracle.html )
( http://oracleadfhowto.blogspot.in/2013/03/consuming-web-service-using-web-service.html )
( http://oracleadfmobile.blogspot.in/2013/03/consuming-soap-web-service-in-adf.html )

But then, as author haven't implemented removeCountries method I tried to create it.
What I did initially was to just add to class Countries this method:



But although compiler wasn't complaining it didn't work. Actually it worked last night (before reboot) but not today.
Must be some SOAP iterator/binding thing or whatever. Or I thought that it worked but in fact it didn't.

Here are original classes:



Then I decided to write (for a start) just plain Java classes and now it looks like this (it works in IDE, not implemented on weblogic server):



This class is just for test it won't go on server (JDeveloper integrated web logic server)




I would like to avoid my own iterator as JDeveloper can generate automatically iterators for webservices, but if I can't get it that way, what would be better way to write above mentioned iterator in removeCountry method?

Is there any way to remove object directly with something like this:



using method



from class Countries?

Parameters should be set by web service iterator.






 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that your class Country does not have an equals() method. The list will call the equals() method to find the element in the list to remove.

So, you'll need to implement a correct equals() method in class Country. And you should also implement the hashCode() method.
 
Nenad Bulatovic
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:The problem is that your class Country does not have an equals() method. The list will call the equals() method to find the element in the list to remove.

So, you'll need to implement a correct equals() method in class Country. And you should also implement the hashCode() method.


OK, if I understood you corectly, this



will call equals() in Country but it will fail as there is no equals() in Country?

Sorry for bothering you, can you give me a hint/example how would you correctly implement both equals() and hashCode() methods in in class Country?
I don't have too much experience with overriding or implementing neither of them in Java.
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The equals() method is notoriously difficult, but you must get it right for your removal to work. Start by looking for the three resources in this thread. Also search this forum and Java in General; there was a long discussion about it about two months ago.
 
Nenad Bulatovic
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it this way, and within "Test Web Service" (with manual imputs of courrse) it works (I can get, add and remove countries, i.e. objects).
I added this into ConutriesProvider application - which provides web service) into Countries class.

Would you agree with this solution?

 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

That breaches the “S” in the “SOLID” principles of object‑oriented programming. That sort of equality test should be done inside the Country object.
 
Campbell Ritchie
Marshal
Posts: 56527
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It also breaches encapsulation in that implementation details (name of fields) are visible outside the Country class.
 
Nenad Bulatovic
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:No.

That breaches the “S” in the “SOLID” principles of object‑oriented programming. That sort of equality test should be done inside the Country object.


OK, will try to rewrite it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!