From: jsimomaa Date: Thu, 17 Oct 2019 18:15:35 +0000 (+0300) Subject: Add configurationBySolverName map to MappingBase X-Git-Tag: v1.43.0~136^2~50 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=b98d8bb2532579435453c7b68c4e94cb369bb86b;p=simantics%2Fplatform.git Add configurationBySolverName map to MappingBase gitlab #402 Change-Id: I3a315e48a79efbcbca73408de8f0f172cf6d8344 --- diff --git a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/MappingBase.java b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/MappingBase.java index 423e5a125..e50d8498d 100644 --- a/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/MappingBase.java +++ b/bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/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; import java.util.function.Consumer; /** @@ -23,7 +24,12 @@ 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 * have been moved somewhere else. @@ -90,6 +96,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) { @@ -141,6 +170,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 @@ -213,6 +244,10 @@ abstract public class MappingBase> { public void dispose() { if (configurationByUid != null) configurationByUid.clear(); + if (configurationBySolverName != null) { + configurationBySolverName.clear(); + configurationBySolverName = null; + } pendingRemoval.clear(); }