From: jsimomaa Date: Fri, 18 Oct 2019 07:05:39 +0000 (+0300) Subject: Add configurationBySolverName map to MappingBase X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=a6114be086cfd4bfda8e445e89da5eac06f11fe3;p=simantics%2Fplatform.git Add configurationBySolverName map to MappingBase gitlab #402 Cherry picked manually from I3a315e48a79efbcbca73408de8f0f172cf6d8344 Change-Id: I0e7ec025e0eb2e0e215661eb92eee8376b83408a --- diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/MappingBase.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/MappingBase.java index 78678b505..aa1afd2f0 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/MappingBase.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/MappingBase.java @@ -6,6 +6,7 @@ import gnu.trove.procedure.TObjectProcedure; import gnu.trove.set.hash.THashSet; import java.io.PrintWriter; +import java.util.Map; /** * The entry point to the mapping structure between Simantics database and a @@ -22,6 +23,11 @@ abstract public class MappingBase> { * Set of all components indexed by their UID. */ transient protected THashMap configurationByUid; + + /** + * Set of all components indexed by their solver name. + */ + transient protected Map configurationBySolverName; /** * Set of components whose removal is delayed because they might @@ -89,6 +95,29 @@ abstract public class MappingBase> { } } + public Map getConfigurationBySolverName() { + Map result = configurationBySolverName; + if (result == null) + result = configurationBySolverName = createConfigurationBySolverName(getConfiguration()); + return result; + } + + protected Map createConfigurationBySolverName(T configuration) { + THashMap configurationBySolverName = new THashMap<>(); + browseConfigurationBySolverName(configurationBySolverName, configuration); + return configurationBySolverName; + } + + private void browseConfigurationBySolverName( + THashMap configurationBySolverName, + T configuration) { + configurationBySolverName.put(configuration.solverComponentName, configuration); + for(T child : configuration.getChildren()) { + browseConfigurationBySolverName(configurationBySolverName, child); + child.parent = configuration; + } + } + public T detachOrCreateComponent(String uid) { T result = configurationByUid.get(uid); if(result == null) { @@ -140,6 +169,8 @@ abstract public class MappingBase> { public void remove(final Solver solver, T component) { if(configurationByUid != null) configurationByUid.remove(component.uid); + if (configurationBySolverName != null) + configurationBySolverName.remove(component.solverComponentName); if(component.getChildMap() != null) component.getChildMap().forEachValue(new TObjectProcedure() { @Override @@ -212,6 +243,10 @@ abstract public class MappingBase> { public void dispose() { if (configurationByUid != null) configurationByUid.clear(); + if (configurationBySolverName != null) { + configurationBySolverName.clear(); + configurationBySolverName = null; + } pendingRemoval.clear(); }