From: jsimomaa Date: Fri, 18 Oct 2019 06:47:22 +0000 (+0300) Subject: Utilize eclipse-collections in AbstractDiagram datastructures X-Git-Tag: v1.43.0~136^2~48 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=124f3b0f3b0c2078432c3bf224914afa9a067512;p=simantics%2Fplatform.git Utilize eclipse-collections in AbstractDiagram datastructures gitlab #404 Change-Id: Ib792edf0c3ef2603e0eb8639bc384faf382a0f92 --- diff --git a/bundles/org.simantics.g2d/META-INF/MANIFEST.MF b/bundles/org.simantics.g2d/META-INF/MANIFEST.MF index 6791f01a0..ee5b50be2 100644 --- a/bundles/org.simantics.g2d/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.g2d/META-INF/MANIFEST.MF @@ -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, diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/impl/AbstractDiagram.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/impl/AbstractDiagram.java index 76b1496bd..7b2ae5f98 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/impl/AbstractDiagram.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/impl/AbstractDiagram.java @@ -11,14 +11,16 @@ *******************************************************************************/ 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 compositionVetoListeners; - ListenerList compositionListeners; + protected ListenerList compositionVetoListeners; + protected ListenerList compositionListeners; - Set elements = new HashSet(); - ArrayList list = new ArrayList(); - List unmodifiableList = Collections.unmodifiableList(list); - volatile List snapshot = null; - DiagramClass clazz; - IHintContext hintCtx; + protected MutableList list = Lists.mutable.empty(); + protected MutableSet elements = Sets.mutable.empty(); + protected volatile ImmutableList 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 getSnapshot() { - List snap = snapshot; + ImmutableList snap = snapshot; if (snap != null) - return snap; + return snap.castToList(); synchronized (this) { snap = snapshot; if (snap == null) - snapshot = snap = Collections.unmodifiableList( new ArrayList(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 getElements() { - return unmodifiableList; + return getSnapshot(); } @Override