aspose file tools*
The moose likes Beginning Java and the fly likes duplicate/unique value count generics list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "duplicate/unique value count generics list" Watch "duplicate/unique value count generics list" New topic
Author

duplicate/unique value count generics list

Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Hi there,

I have a scenario where in I would need to get a count of duplicate objects and unique objects from a generics list based on attribute values of the object in the generics list.
The generics list collection comprises of this custom java object.
Class Apartment {
int aptNo; int lcnNo;
}
Based on the above instance attribute values I have to find count of duplicates/uniques in the generics collection.
All duplicates (based on value of aptNo)
All uniques (based on value of lcnNo)

Let me know your thoughts on the same.

-Uday
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11473
    
  16

I don't think your question is very clear...

you have some kind of list that holds Apartment objects, I take it. When you say "duplicate objects", are you talking about java objects on the heap, or do you mean you want to know if two Apartment objects are functionally equal?

This List has the same object duplicated in the list:

Apartment A = new Apartment();
myList.add(A);
myList.add(A);



This has two different java objects, but they are for all intents and purposes equal

Apartment A = new Apartment(101, 11);
Apartment B = new Apartment(101, 11);
myList.add(A);
myList.add(B);


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
I mean functionally equal. The problem I am facing is with override of the equals method.
Basically I am looking at creating a HashSet from this List so that I can skip the duplicates and get the unique count.
My intent here is to get a count of Apartment objects with unique lcnNo values.
So say if I use the lcnNo as differentiator in the equals and hashcode method and when I convert the aforementioned list to a HashSet I get all the Apartment objects with unique lcnNo. This works.

But there is another requirement where in I need to get all objects with unique aptNo value.

Is there any other way to grab such "functionally" unique objects w/o resorting to equals/hashcode differentiator for the same.

-Uday
Udayan Kumar
Ranch Hand

Joined: Jan 16, 2007
Posts: 66
Can someone provide help or pointers on how can i resolve the same

Thanks in Advance,
Uday
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: duplicate/unique value count generics list