From: Marko Luukkainen Date: Fri, 12 Mar 2021 14:44:44 +0000 (+0200) Subject: Fix CollectionUtils.unique (removed unique items) X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F4677%2F1;p=simantics%2Fplatform.git Fix CollectionUtils.unique (removed unique items) gitlab #679 Change-Id: I4c297a9a3ed258e16b2cd3663b63115748c6ae61 --- diff --git a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/collections/CollectionUtils.java b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/collections/CollectionUtils.java index 720d0193a..8d962a1a3 100644 --- a/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/collections/CollectionUtils.java +++ b/bundles/org.simantics.utils.datastructures/src/org/simantics/utils/datastructures/collections/CollectionUtils.java @@ -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--;