Fix RamListComponent to allow elements with same name

Issue #351 resolved
Cécile Camillieri created an issue

The idea is to allow the user to add several elements with the same name in the list. First solution introduced decided that elements with the same sorting name would be differenciated automatically by the Comparator.

So for example, if A and B have the same sorting name compare(A,B) , will return A<B. This is not correct: Let's say I have two elements A and B that have the same sorting name. When adding B to the map, it will call compare(A,B) and so we have B>A. B will be placed in a branch right of A.

Later on when I want to get the element for B, the comparator will be used, so if at that point compare(B,A) is called, I will the result that B<A, it will look in the wrong branch of the tree, and return null, even if the element is in the map.

==========================

To prevent any crashes from happening because of this, the default comparator now uses the sorting name followed by the default toString() of the objects. This way all of them should be unique.

However it may be a good idea to find another solution, because this one looks a lot like a hack. One solution would be that the getSortingName method is called only once, when an element is added to the list. This name would be stored in a map<Element, SortingName> and this map will be used all the time to get the sorting name, instead of calling getSortingName() each time. If the user gives us a name that is already present in the values of the map, we could use the createUniqueName(...) method from COREModelUtils to make it completely unique.

Comments (9)

  1. Matthias Schoettle
    • changed status to open

    With the fixes there is now a problem when the same constraint fails more than once (previously that worked):

    • Create a class A
    • Create another class A

    The unique name constraint shows up for both, but only one will be visible (there is an error in the console).

    A reason seems to be the elementsOrder comparator. The validator has one that sorts by severity.

  2. Cécile Camillieri reporter

    References #351: Remove custom comparator for validationView, now use default comparator to order validation errors with sortingName.

    → <<cset 0eaaaa850885>>

  3. Log in to comment