aspose file tools*
The moose likes Beginning Java and the fly likes Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated." Watch "Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated." New topic
Author

Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated.

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

I have a list of items in my list and some of these items are duplicates that were added, at the customer's request because she wanted a message after the add to be displayed to the customer that they could not add a duplicate item to this list. The user then clicks on the duplicate item and we need to remove that duplicate item and not all the original item that match that item number. All I've been seeing when googling is a way to remove ALL duplicate items and not just the record that was added that is considered a duplicate.

My code is below and I need to determine the last duplicate item and then delete that one item by passing in that last duplicate item to my deleteItem() below and keep the original item it duplicated. Any help would be greatly appreciated.

John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Melinda:

How do you know which item is the duplicate?

John.
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

I thought I had my problem resolved given an answer I found in the archives of this forum. However, I am still having a problem. I was able to remove the duplicate records from the list using the HashSet since HashSet does not allow duplicates.

However, my question is since I'm setting aSet to a new HashSet using items it would seem that aSet will always find records that will reside in items or am I thinking incorrectly here?

If the object duplicateItems is NOT populated then I just want to delete the items sent to this method but duplicateItems is constantly being populated and I just want it populated if duplicates are found in items.

ANY Help is appreciated. Regards.

In my code here:

Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
How about



I'll leave it as an exercise for you to figure out how to make this more efficient and more generic (for easier reuse).


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Garrett,

Thanks for the help. I will try it and hopefully this will resolve my problem. Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help - Remove only the duplicated ITEM and NOT the original item that was duplicated.