You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2015/06/11 15:55:00 UTC

[jira] [Updated] (COLLECTIONS-439) TreeBag with comparator does not store non-key duplicates.

     [ https://issues.apache.org/jira/browse/COLLECTIONS-439?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Neidhart updated COLLECTIONS-439:
----------------------------------------
    Attachment: BagTest.java

I looked into this contribution again, and I must say that I have changed my mind; this will not make it into collections for the following reasons:

 * the datastructure would violate the Collection contract: we did this in the past and it was a mistake. Currently we are trying hard to clean up all this violations.
 * the Bag interface is going to be deprecated with 4.1 and replaced by a MultiSet interface without violations of the Collection contract
 * the provided KeySortedBag does not comply to the Bag interface contract, several methods do something different
 * the overall use-case is vague, and some of the implemented tests are really confusing and I would be surprised by a datastructure with such a behavior

I have also attached an example how to properly use a SortedBag with comparators that uses multiple keys.

This kind of datastructure might still be of use, but it should not be added to a general-purpose library like collections.

> TreeBag with comparator does not store non-key duplicates.
> ----------------------------------------------------------
>
>                 Key: COLLECTIONS-439
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-439
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Bag
>    Affects Versions: 3.2.1
>            Reporter: Claude Warren
>             Fix For: 4.x
>
>         Attachments: BagTest.java, COLLECTIONS-439.tar.gz, SortedBag.java
>
>
> When storing objects that are sorted by a Comparator, if the differences in the objects are not in the comparator the same version of the object is returned.  I expected that the sorted bag would work like a DB table with a non-unique key -- ordered but duplicate only determined by Object.equals().
> I have implemented this type of bag using a TreeMap of List.  My implementation uses the Jena ExtendedIterator to make building the iterator() and array() methods easier.
> Will attach the code.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)