]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Utilize eclipse-collections in AbstractDiagram datastructures 63/3363/1
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 18 Oct 2019 06:47:22 +0000 (09:47 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 18 Oct 2019 06:47:22 +0000 (09:47 +0300)
gitlab #404

Change-Id: Ib792edf0c3ef2603e0eb8639bc384faf382a0f92

bundles/org.simantics.g2d/META-INF/MANIFEST.MF
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/impl/AbstractDiagram.java

index 6791f01a0ce1ccfa0b6a7b1628a5a19a3e220614..ee5b50be248ceeb7b314a94e0b0cc664f1c91d0b 100644 (file)
@@ -21,7 +21,9 @@ Require-Bundle: org.eclipse.core.runtime,
  org.simantics.datatypes;bundle-version="1.0.0",
  org.simantics.db;bundle-version="1.1.0",
  org.simantics.ui;bundle-version="1.0.0",
- org.slf4j.api
+ org.slf4j.api,
+ org.eclipse.collections.eclipse-collections-api,
+ org.eclipse.collections.eclipse-collections
 Export-Package: org.simantics.g2d.canvas,
  org.simantics.g2d.canvas.impl,
  org.simantics.g2d.chassis,
index 76b1496bdc064d108a955e3ab62f2e32ed96ef73..7b2ae5f986a772bda7e1edbc4b0c8b73fab53034 100644 (file)
  *******************************************************************************/
 package org.simantics.g2d.diagram.impl;
 
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
+import org.eclipse.collections.api.list.ImmutableList;
+import org.eclipse.collections.api.list.MutableList;
+import org.eclipse.collections.api.set.MutableSet;
+import org.eclipse.collections.impl.factory.Lists;
+import org.eclipse.collections.impl.factory.Sets;
 import org.simantics.g2d.diagram.DiagramClass;
 import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.g2d.diagram.handler.DiagramAdapter;
@@ -35,15 +37,14 @@ import org.simantics.utils.threads.IThreadWorkQueue;
  */
 public class AbstractDiagram implements IDiagram {
 
-    ListenerList<CompositionVetoListener> compositionVetoListeners;
-    ListenerList<CompositionListener>     compositionListeners;
+    protected ListenerList<CompositionVetoListener> compositionVetoListeners;
+    protected ListenerList<CompositionListener>     compositionListeners;
 
-    Set<IElement>                         elements         = new HashSet<IElement>();
-    ArrayList<IElement>                   list             = new ArrayList<IElement>();
-    List<IElement>                        unmodifiableList = Collections.unmodifiableList(list);
-    volatile List<IElement>               snapshot         = null;
-    DiagramClass                          clazz;
-    IHintContext                          hintCtx;
+    protected MutableList<IElement>                 list             = Lists.mutable.empty();
+    protected MutableSet<IElement>                  elements         = Sets.mutable.empty();
+    protected volatile ImmutableList<IElement>      snapshot         = null;
+    private DiagramClass                            clazz;
+    protected IHintContext                          hintCtx;
 
     public AbstractDiagram(DiagramClass clazz, IHintContext hintCtx)
     {
@@ -85,7 +86,6 @@ public class AbstractDiagram implements IDiagram {
             e.dispose();
         }
 
-        elements.clear();
         list.clear();
         snapshot = null;
 
@@ -138,8 +138,8 @@ public class AbstractDiagram implements IDiagram {
         }
 
         snapshot = null;
-        elements.add(e);
         list.add(e);
+        elements.add(e);
 
         e.addedToDiagram(this);
 
@@ -232,15 +232,15 @@ public class AbstractDiagram implements IDiagram {
 
     @Override
     public List<IElement> getSnapshot() {
-        List<IElement> snap = snapshot;
+        ImmutableList<IElement> snap = snapshot;
         if (snap != null)
-            return snap;
+            return snap.castToList();
         synchronized (this) {
             snap = snapshot;
             if (snap == null)
-                snapshot = snap = Collections.unmodifiableList( new ArrayList<IElement>(list) );
+                snapshot = snap = list.toImmutable();
         }
-        return snap;
+        return snap.castToList();
     }
 
     protected static void fireDestroyed(IDiagram e)
@@ -435,7 +435,7 @@ public class AbstractDiagram implements IDiagram {
 
     @Override
     public List<IElement> getElements() {
-        return unmodifiableList;
+        return getSnapshot();
     }
 
     @Override