Hi Tomaž! Quikee wrote: > In what way should remove_all work in case of removing the same items. > Currently there is an inconsistency in this behavior from remove_all > on AbstractCollection and the implementation in ArrayList. > The AbstractCollection implementation will call remove for every > element which will in case of n same items in list 1 and m same items > in incoming list 2 remove n-m items. > > For example: > list1 has items 1,1,1,1,1 and list2 has items 1,1,1 > after remove_all in list1 would remain items 1,1 > > The implementation on ArrayList will always remove all items from the > list if the incoming list has such an item. > So in the same example as above list1 after the call would not have any items. > > I have looked also how Java's ArrayList behaves in such a case and it > did behave in a different way as above. The Java's ArrayList treated > the incomming collection as a set and did delete only one element from > the list1. > So the example would look like this: > list1 has items 1,1,1,1,1 and list2 has items 1,1,1 > after remove_all in list1 would remain items 1,1,1,1 > > Which of this behavior would you prefer?
That's a good thing you point here. IMHO we should explicit API contracts in the collection interfaces. I would prefer that remove is said to remove the first element. And that remove_all removes every element instances. IMHO this will enable to respect the same API contract for multi-sets. As you can read in Apache Commons Collections, which build upon and derives from Java Collections, their Bag interfaces explicitly override the defined behavior for contains|remove|*All methods. [1] Thus I would prefer if our Collection interface already defines a such API contract: remove_all removes all the element occurrences. In simple sets, it would obviously remove only one instance. Best regards, Didier. [1] http://commons.apache.org/collections/apidocs/org/apache/commons/collections/Bag.html#removeAll(java.util.Collection) _______________________________________________ Vala-list mailing list Vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list