DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Add ability to specify custom comparor for Set operations (difference, intersection) #1395

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

It would be great to be able to specify a custom predicate that takes two 
values (one from each set) and allows the user to specify equality. 

For example:

Sets.difference(set1, set2, new PredicatePair<T, bool>){
   @Override
   public bool apply(T item1, T item2){
      return someBoolFunction(item1, item2);
   }
}

Original issue reported on code.google.com by romandvoskin on 30 Apr 2013 at 8:06

GoogleCodeExporter commented 9 years ago
How could this possibly be done efficiently, especially as a view?

We've rejected requests for sets or maps based on an Equivalence in the past.

Original comment by wasserman.louis on 30 Apr 2013 at 11:59

GoogleCodeExporter commented 9 years ago
Are you not calling .equals() already? Why not simply replace that call
with one to the custom predicate?

Original comment by romandvoskin on 1 May 2013 at 12:04

GoogleCodeExporter commented 9 years ago
No, we aren't, we're calling Set.contains, which has a baked in notion of 
equality.

Original comment by wasserman.louis on 1 May 2013 at 12:07

GoogleCodeExporter commented 9 years ago
This can't possibly be done in a way with performance and semantics consistent 
with the preexisting Sets.difference and other utilities.

Original comment by lowas...@google.com on 3 May 2013 at 9:17

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08