You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Felix Knecht <fe...@otego.com> on 2010/05/20 14:18:47 UTC
equals() implementation in ProtectedItem
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Are you aware, that this [1] is an equal of collections and will return
in most cases "false" as it is a reference comparison [2]?
Is this wanted?
Felix
[1]
http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/aci/ProtectedItem.html#245
[2]
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collection.html#equals%28java.lang.Object%29
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkv1KKcACgkQ2lZVCB08qHFNkQCdHSeU7HA5yGhvLBYMOyoySzIK
dAgAoMTL3bqG80HS98Gmqmu0JDax/wVe
=xP9F
-----END PGP SIGNATURE-----
Re: equals() implementation in ProtectedItem
Posted by Stefan Seelmann <se...@apache.org>.
Stefan Seelmann schrieb:
> Felix Knecht wrote:
>>>> Are you aware, that this [1] is an equal of collections and will return
>>>> in most cases "false" as it is a reference comparison [2]?
>> Thanks to test cases :)
>>> I checked the history. Previously we didn't use
>>> Collections.unmodifiableCollection( attributeTypes )
>>> And a quick check shows that the callers of the construtor always pass
>>> an java.util.Set.
>>> For two Sets the equals method would work correctly, but the creation of
>>> the unmodifyalbe collection not.
>>> I think we have two options:
>>> - use CollectionUtils.isEqualCollection() from commons collections, this
>>> seems to do the right thing.
>>> - try to change the parameter type from Collection to Set in the
>>> constructors and use Collections.unmodifiableSet() instead.
>>> Thoughts?
>> It dependes on the content we have in the collections. Set doesn't
>> allows duplicates wheras with certain collection implementations this is
>> possible.
>>
>
> I checked X.501 specification [1], Annex E, page 173. It clearly states
> that in ProtectedItem all elments (attributeType, allAttributeValues,
> attributeValue, selfValue, maxValueCount, restrictedBy) are *sets*.
>
> I'm going to change all Collection types to Sets and activate your tests.
Done. Thanks Felix for the test cases :-)
Kind Regards,
Stefan
Re: equals() implementation in ProtectedItem
Posted by Stefan Seelmann <se...@apache.org>.
Felix Knecht wrote:
>>> Are you aware, that this [1] is an equal of collections and will return
>>> in most cases "false" as it is a reference comparison [2]?
>
> Thanks to test cases :)
>> I checked the history. Previously we didn't use
>> Collections.unmodifiableCollection( attributeTypes )
>> And a quick check shows that the callers of the construtor always pass
>> an java.util.Set.
>
>> For two Sets the equals method would work correctly, but the creation of
>> the unmodifyalbe collection not.
>
>> I think we have two options:
>> - use CollectionUtils.isEqualCollection() from commons collections, this
>> seems to do the right thing.
>> - try to change the parameter type from Collection to Set in the
>> constructors and use Collections.unmodifiableSet() instead.
>
>> Thoughts?
>
> It dependes on the content we have in the collections. Set doesn't
> allows duplicates wheras with certain collection implementations this is
> possible.
>
I checked X.501 specification [1], Annex E, page 173. It clearly states
that in ProtectedItem all elments (attributeType, allAttributeValues,
attributeValue, selfValue, maxValueCount, restrictedBy) are *sets*.
I'm going to change all Collection types to Sets and activate your tests.
Kind Regards,
Stefan
[1] http://www.itu.int/rec/T-REC-X.501-200508-I
Re: equals() implementation in ProtectedItem
Posted by Felix Knecht <fe...@apache.org>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>> Are you aware, that this [1] is an equal of collections and will return
>> in most cases "false" as it is a reference comparison [2]?
Thanks to test cases :)
>
> I checked the history. Previously we didn't use
> Collections.unmodifiableCollection( attributeTypes )
> And a quick check shows that the callers of the construtor always pass
> an java.util.Set.
>
> For two Sets the equals method would work correctly, but the creation of
> the unmodifyalbe collection not.
>
> I think we have two options:
> - use CollectionUtils.isEqualCollection() from commons collections, this
> seems to do the right thing.
> - try to change the parameter type from Collection to Set in the
> constructors and use Collections.unmodifiableSet() instead.
>
> Thoughts?
It dependes on the content we have in the collections. Set doesn't
allows duplicates wheras with certain collection implementations this is
possible.
>> [1]
>> http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/aci/ProtectedItem.html#245
>> [2]
>> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collection.html#equals%28java.lang.Object%29
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkv2RBsACgkQ2lZVCB08qHEMRwCgqw/vU0yLW9MLaxJu84yseUiO
LtwAn0L5ez3u/jYUA0CIkfsT68qi371a
=hQz9
-----END PGP SIGNATURE-----
Re: equals() implementation in ProtectedItem
Posted by Stefan Seelmann <se...@apache.org>.
Felix Knecht schrieb:
> Are you aware, that this [1] is an equal of collections and will return
> in most cases "false" as it is a reference comparison [2]?
>
> Is this wanted?
I don't think that is wanted.
I checked the history. Previously we didn't use
Collections.unmodifiableCollection( attributeTypes )
And a quick check shows that the callers of the construtor always pass
an java.util.Set.
For two Sets the equals method would work correctly, but the creation of
the unmodifyalbe collection not.
I think we have two options:
- use CollectionUtils.isEqualCollection() from commons collections, this
seems to do the right thing.
- try to change the parameter type from Collection to Set in the
constructors and use Collections.unmodifiableSet() instead.
Thoughts?
Kind Regards,
Stefan
>
> Felix
>
> [1]
> http://people.apache.org/~felixk/shared-docs/xref/org/apache/directory/shared/ldap/aci/ProtectedItem.html#245
> [2]
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collection.html#equals%28java.lang.Object%29