commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodney Waldhoff <rwaldh...@apache.org>
Subject RE: [collections] testing equality of collections wrt some Comparator
Date Mon, 21 Apr 2003 14:46:53 GMT
On Mon, 21 Apr 2003, Pablo Nussembaum wrote:

> I think that you don't need commons-collection to do this
> If you implement Comparable in the class Person, you could write this
> code:
>
> if (collection1.size() == collection2.size() &&
> collection1.equals(collection2)) {
> 	System.out.println("the collections are equals");
> }
> else{
> 	System.out.println("the collections are not equals");
> }
>
> If you use a List de elements has to be in same order, and if use a Set
> the order of the elements not mater.

Not in Mischa's implementation.  PersonComparator.compare(x,y) == 0 does
not imply x.equals(y).  Whether this is a good idea or a bad idea might be
a topic for discussion, but I think it's legitimate to suggest that there
are times when you want different notions of "equality" or "equivalence".


Mime
View raw message