public static final String VAR_STOP = "stopTime";
public static final String VAR_STEP = "timeStep";
+ static String configurationName(Configuration c) {
+ ModuleType moduleType = c.getModuleType();
+ if(moduleType == null) {
+ return "Model";
+ } else {
+ return moduleType.getName();
+ }
+ }
+
/**
* Write a collection of configurations into a single Modelica code
* @param isGame
*/
public static String write(Collection<Configuration> _configurations, double startTime, double stopTime, double timeStep, boolean isGame, String omVersion) {
+
ArrayList<Configuration> configurations = new ArrayList<Configuration>(_configurations);
Collections.sort(configurations, new Comparator<Configuration>() {
-
+
+ Configuration findConfiguration(ModuleType type) {
+ for(Configuration c : _configurations) {
+ if(type.equals(c.getModuleType())) {
+ return c;
+ }
+ }
+ return null;
+ }
+
boolean uses(Configuration o1, Configuration o2) {
ModuleType type = o2.getModuleType();
if(type == null) return false;
Module m = (Module)e;
if(m.getType().equals(type)) {
return true;
+ } else {
+ Configuration c = findConfiguration(m.getType());
+ if(c != null) {
+ return uses(c, o2);
+ }
}
}
}
public int compare(Configuration o1, Configuration o2) {
if(uses(o1, o2)) return 1;
else if(uses(o2, o1)) return -1;
- else return 0;
+ else return configurationName(o1).compareTo(configurationName(o2));
}
});