]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fix CollectionUtils.unique (removed unique items) 77/4677/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 12 Mar 2021 14:44:44 +0000 (16:44 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 12 Mar 2021 14:44:44 +0000 (16:44 +0200)
gitlab #679

Change-Id: I4c297a9a3ed258e16b2cd3663b63115748c6ae61

bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/collections/CollectionUtils.java

index 720d0193a3de2bbe1e676fccd65aa73653dbd2ff..8d962a1a3ee980a6a93e4bebf1d0ee4230340923 100644 (file)
@@ -217,15 +217,13 @@ public final class CollectionUtils {
      * Remove elements that appear more than once. Keep order otherwise.
      * @param list to be pruned
      */
-    public static void unique(List<?> list) {
-       int c = list.size();
-       int i = c-1;
+    public static void unique(List<?> list) { 
+       int i = list.size()-1;
        while (i>0) {
                Object o = list.get(i);
                int index = list.indexOf(o);
-               if (index>=0) {
+               if (index>=0 && index < i) {
                        list.remove(index);
-                       c--;
                        i--;
                } else {
                        i--;