
Hello Alex, On 29/05/14 16:05, Alexander Wels wrote:
Hi guys,
I have a question about the SortedListModel. If you look at the setItems(Collection<T> value) method. You will notice that eventually all the items are added to a SortedSet. This is not a problem if all the elements of your collection are different. But what happens if the elements of your collection are not all different. More specifically if I pass in a comparator that matches on a field of the object that is not different like description, or size or something of that nature.
The set will reduce the number of elements. Before I change it to be a list that can have duplicates, I would like to know the origin of the set and if there are going to be any issues when I do that.
It was originally conceived as a way to consistently keep items in a sorted manner, whether they're added via setItems() or getItems().add(). It had nothing to do with the fact that duplicates aren't allowed, so I doubt a change will adversely affect current uses (of which there aren't many, if I'm not mistaken, so it's better to verify). However, a list doesn't automatically sort itself as items are added, so you should preserve that functionality if you decide to change the implementation. You could implement a customized List that invokes sort() upon add(). I think the current implementation is far more efficient in that insertion and removal is done in O(logn), whereas the alternative would be O(n). You might say that's not important, I think it might be important for scalability in the future. But frankly, it's not difficult to notice what one inserts into their SortedListModel, and to make sure that its equals() method is consistent with what they're trying to achieve (or wrap the items in case it isn't).
Thanks, Alexander _______________________________________________ Devel mailing list Devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/devel