Fix RamListComponent to allow elements with same name
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)
-
reporter -
reporter References
#351: prevent crash of RamListComponent if items with the same sorting name are added.→ <<cset bccce88e8e9a>>
-
reporter - edited description
-
References
#351: Create a map that contains the sorting names. The goal name are created using CoreModelUtil.createUniqueName()→ <<cset 35887989ca6a>>
-
reporter References
#351: fix default comparator for the ramListComponent→ <<cset 46b8b1df9979>>
-
reporter - changed status to resolved
-
- 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. -
reporter References
#351: Remove custom comparator for validationView, now use default comparator to order validation errors with sortingName.→ <<cset 0eaaaa850885>>
-
- changed status to resolved
- Log in to comment
cleanup in RamListComponents + temp fix to avoid crash in TracingView when reusing the same concern more than twice (see issue
#351)→ <<cset 6e996a9dede0>>