implemented removal of old routes when new routes are searched

This commit is contained in:
Stephan Richter
2020-12-04 11:55:38 +01:00
parent e2e983ec44
commit 33d596f5c3
7 changed files with 23 additions and 12 deletions

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>1.2.15</version>
<version>1.2.16</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

View File

@@ -387,6 +387,7 @@ public abstract class BaseClass implements Constants{
}
public BaseClass remove() {
LOG.debug("Called remove on {} ({})",id(),this);
if (isSet(parent)) parent.removeChild(this);
return registry.remove(id());
}

View File

@@ -249,18 +249,23 @@ public class Plan extends BaseClass{
* @return a string giving information how many routes have been found
*/
private String analyze() {
Vector<Route> routes = new Vector<Route>();
List<Route> oldRoutes = BaseClass.listElements(Route.class);
Vector<Route> newRoutes = new Vector<Route>();
for (Block block : BaseClass.listElements(Block.class)) {
if (block.name.equals("Huhu")) {
System.err.println("Here we go!");
}
for (Connector con : block.startPoints()) {
routes.addAll(follow(new Route().begin(block,con.from.inverse()),con));
newRoutes.addAll(follow(new Route().begin(block,con.from.inverse()),con));
}
}
for (Tile tile : BaseClass.listElements(Tile.class)) tile.routes().clear();
for (Route route : routes) registerRoute(route.complete());
return t("Found {} routes.",routes.size());
for (Route route : newRoutes) registerRoute(route.complete());
for (Route oldRoute : oldRoutes) {
oldRoute.id = new Id("test"); // new routes may have the same ids and shall not be deleted in the next step!
oldRoute.remove();
}
return t("Found {} routes.",newRoutes.size());
}
/**

View File

@@ -286,8 +286,12 @@ public class Route extends BaseClass implements Comparable<Route>{
public void addPropertiesFrom(Route existingRoute) {
LOG.debug("addPropertiesFrom({})",existingRoute);
disabled = existingRoute.disabled;
conditions.addAll(existingRoute.conditions);
for (Condition condition : existingRoute.conditions) { // bestehende Bedingungen der neuen zuweisen
condition.parent(this);
conditions.add(condition);
}
conditions.forEach(condition -> existingRoute.conditions.removeChild(condition));
for (Entry<String, ActionList> entry : triggeredActions.entrySet()) {
String trigger = entry.getKey();
@@ -469,7 +473,7 @@ public class Route extends BaseClass implements Comparable<Route>{
}
public Id id() {
if (id == null) id = new Id(""+(generateName().hashCode()));
if (isNull(id)) id = new Id(""+(generateName().hashCode()));
return id;
}
@@ -748,7 +752,7 @@ public class Route extends BaseClass implements Comparable<Route>{
}
@Override
public BaseClass remove() {
public BaseClass remove() {
super.remove();
if (isSet(train)) train.removeChild(this);
path.forEach(tile -> tile.removeChild(this));

View File

@@ -74,11 +74,12 @@ public class ActionList extends Action implements Iterable<Action>{
}
if (exists) {
LOG.debug("action not added.");
} else {
} else { // bestehemde Aktion der neuen Liste zuweisen
this.add(otherAction);
LOG.debug("action added.");
}
}
actions.forEach(action -> other.removeChild(action)); // zugewiesene Aktionen von alter Liste löschen
}
public boolean drop(Action action) {

View File

@@ -132,7 +132,7 @@ public class ConditionList extends Condition implements Iterable<Condition>{
}
@Override
protected void removeChild(BaseClass child) {
public void removeChild(BaseClass child) {
conditions.remove(child);
}

View File

@@ -389,7 +389,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
@Override
public void removeChild(BaseClass child) {
routes.remove(child);
shadows.remove(child);
if (child instanceof Shadow) shadows.remove(child);
if (child == train) train = null;
if (child == route) route = null;
plan.place(this);