import gnu.trove.set.hash.THashSet;
import java.io.PrintWriter;
+import java.util.Map;
import java.util.function.Consumer;
/**
* Set of all components indexed by their UID.
*/
transient protected THashMap<String, T> configurationByUid;
-
+
+ /**
+ * Set of all components indexed by their solver name.
+ */
+ transient protected Map<String, T> configurationBySolverName;
+
/**
* Set of components whose removal is delayed because they might
* have been moved somewhere else.
}
}
+ public Map<String, T> getConfigurationBySolverName() {
+ Map<String, T> result = configurationBySolverName;
+ if (result == null)
+ result = configurationBySolverName = createConfigurationBySolverName(getConfiguration());
+ return result;
+ }
+
+ protected Map<String, T> createConfigurationBySolverName(T configuration) {
+ THashMap<String, T> configurationBySolverName = new THashMap<>();
+ browseConfigurationBySolverName(configurationBySolverName, configuration);
+ return configurationBySolverName;
+ }
+
+ private void browseConfigurationBySolverName(
+ THashMap<String, T> 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) {
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<T>() {
@Override
public void dispose() {
if (configurationByUid != null)
configurationByUid.clear();
+ if (configurationBySolverName != null) {
+ configurationBySolverName.clear();
+ configurationBySolverName = null;
+ }
pendingRemoval.clear();
}