java - Can we override the intersection method of Guava to compare objects? -


i have tried compare sets of type string using sets.intersection method() in guava. works fine. want know method should implement compare 2 objects? have overridden compareto() method sets.intersection treat similar objects different. can advice please?

thanks.

given implementation of sets.intersection():

public static <e> setview<e> intersection(final set<e> set1, final set<?> set2) {     //...     return new setview<e>() {       //...       @override public boolean contains(object object) {         return set1.contains(object) && set2.contains(object);       }       @override public boolean containsall(collection<?> collection) {         return set1.containsall(collection)             && set2.containsall(collection);       }     };   } 

i'd have implement whatever methods needed make contains() , containsall() work sets pass in, because work delegated sets pass in.

so hashsets equals() , hashcode(), , treesets compareto() if implement comparable or compare() if use comparator (probably want still override equals() , hashcode() keep things consistent outside map too).


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -