Skip to content
Snippets Groups Projects
Commit ff631d60 authored by Johannes Mey's avatar Johannes Mey
Browse files

cleanup and improve

parent 57bd902b
No related branches found
No related tags found
No related merge requests found
aspect TreeNavigation { aspect TreeNavigation {
// collections of things
syn Collection<Segment> RailwayContainer.segments() {
java.util.List<Segment> segments = new ArrayList<>();
for (Region region : getRegionList()) {
for (TrackElement trackElement : region.getTrackElementList()) {
Segment segment = trackElement.asSegment();
if (segment != null) segments.add(segment);
}
}
return segments;
}
syn Collection<Switch> RailwayContainer.switches() { syn Collection<Switch> RailwayContainer.switches() {
java.util.List<Switch> switches = new ArrayList<>(); java.util.List<Switch> switches = new ArrayList<>();
for (Region region : getRegionList()) { for (Region region : getRegionList()) {
...@@ -33,36 +20,6 @@ aspect TreeNavigation { ...@@ -33,36 +20,6 @@ aspect TreeNavigation {
return switches; return switches;
} }
syn Collection<Semaphore> RailwayContainer.semaphores() {
java.util.List<Semaphore> semaphores = new ArrayList<>();
for (Segment segment : segments()) {
for (Semaphore semaphore : segment.getSemaphoreList()) {
semaphores.add(semaphore);
}
}
return semaphores;
}
syn Collection<Sensor> RailwayContainer.sensors() {
java.util.List<Sensor> sensors = new ArrayList<>();
for (Region region : getRegionList()) {
for (Sensor sensor : region.getSensorList()){
sensors.add(sensor);
}
}
return sensors;
}
// more reference resolving
syn Collection<TrackElement> Sensor.monitoredElements() {
java.util.List<TrackElement> trackElements = new ArrayList<>();
for (TrackElement trackElement : getMonitoredElementList()) {
trackElements.add(trackElement);
}
return trackElements;
}
syn Collection<Segment> Sensor.monitoredSegments() { syn Collection<Segment> Sensor.monitoredSegments() {
java.util.List<Segment> segments = new ArrayList<>(); java.util.List<Segment> segments = new ArrayList<>();
for (TrackElement trackElement : getMonitoredElementList()) { for (TrackElement trackElement : getMonitoredElementList()) {
...@@ -85,22 +42,6 @@ aspect TreeNavigation { ...@@ -85,22 +42,6 @@ aspect TreeNavigation {
return switches; return switches;
} }
syn TrackElement Sensor.monitoredElement(int i) {
return getMonitoredElement(i);
}
syn Sensor Route.requiredSensor(int i) {
return getRequiredSensor(i);
}
syn Collection<TrackElement> TrackElement.connectsTos() {
java.util.List<TrackElement> trackElements = new ArrayList<>();
for (TrackElement trackElement : getConnectsToList()) {
trackElements.add(trackElement);
}
return trackElements;
}
syn Collection<Segment> TrackElement.connectsToSegments() { syn Collection<Segment> TrackElement.connectsToSegments() {
java.util.List<Segment> segments = new ArrayList<>(); java.util.List<Segment> segments = new ArrayList<>();
for (TrackElement trackElement : getConnectsToList()) { for (TrackElement trackElement : getConnectsToList()) {
...@@ -112,34 +53,4 @@ aspect TreeNavigation { ...@@ -112,34 +53,4 @@ aspect TreeNavigation {
return segments; return segments;
} }
syn Collection<Sensor> Route.requiredSensors() {
java.util.List<Sensor> sensors = new ArrayList<>();
for (Sensor sensor : getRequiredSensorList()) {
sensors.add(sensor);
}
return sensors;
}
syn Collection<Route> Sensor.requiringRoutes() {
return getRoot().requiringRoutesMap().get(this.id());
}
syn Map<Integer,Set<Route>> RailwayContainer.requiringRoutesMap() {
Map<Integer,Set<Route>> routeMap = new java.util.HashMap<Integer,Set<Route>>();
// fill the keys
for (Sensor sensor: sensors()) {
routeMap.put(sensor.id(), new java.util.HashSet());
}
// update the values
for (Route route : getRouteList()) {
for (Sensor sensor : route.getRequiredSensorList()) {
routeMap.get(sensor.getId()).add(route);
}
}
return routeMap;
}
} }
...@@ -12,7 +12,7 @@ aspect Queries { ...@@ -12,7 +12,7 @@ aspect Queries {
java.util.List<JastaddRouteSensorMatch> matches = new java.util.ArrayList<>(); java.util.List<JastaddRouteSensorMatch> matches = new java.util.ArrayList<>();
// if the route follows a switch and this switch has is monitored by a sensor // if the route follows a switch and this switch has is monitored by a sensor
Collection<Sensor> requiredSensors = requiredSensors(); RefList<Sensor> requiredSensors = getRequiredSensorList();
for (SwitchPosition sp : getSwitchPositionList()) { for (SwitchPosition sp : getSwitchPositionList()) {
Switch sw = sp.target(); Switch sw = sp.target();
for (Sensor sensor : sw.getMonitoringSensorList()) { for (Sensor sensor : sw.getMonitoringSensorList()) {
...@@ -41,7 +41,7 @@ aspect Queries { ...@@ -41,7 +41,7 @@ aspect Queries {
syn Collection<JastaddRouteSensorInjectMatch> Route.routeSensorInjectMatches() { syn Collection<JastaddRouteSensorInjectMatch> Route.routeSensorInjectMatches() {
java.util.List<JastaddRouteSensorInjectMatch> matches = new ArrayList<JastaddRouteSensorInjectMatch>(); java.util.List<JastaddRouteSensorInjectMatch> matches = new ArrayList<JastaddRouteSensorInjectMatch>();
for (Sensor sensor: requiredSensors()) { for (Sensor sensor: getRequiredSensorList()) {
matches.add(new JastaddRouteSensorInjectMatch(this, sensor)); matches.add(new JastaddRouteSensorInjectMatch(this, sensor));
} }
return matches; return matches;
......
...@@ -16,11 +16,11 @@ aspect Queries { ...@@ -16,11 +16,11 @@ aspect Queries {
Semaphore exitSemaphore = this.exit(); Semaphore exitSemaphore = this.exit();
// get the sensors of the route // get the sensors of the route
for (Sensor sensor1 : this.requiredSensors()) { for (Sensor sensor1 : this.getRequiredSensorList()) {
for (TrackElement te1 : sensor1.getMonitoredElementList()) { for (TrackElement te1 : sensor1.getMonitoredElementList()) {
for (TrackElement te2 : te1.connectsTos()) { for (TrackElement te2 : te1.getConnectsToList()) {
for (Sensor sensor2 : te2.getMonitoringSensorList()) { for (Sensor sensor2 : te2.getMonitoringSensorList()) {
for (Route route2 : sensor2.requiringRoutes()) { for (Route route2 : sensor2.getRequiringRouteList()) {
if (this != route2) { if (this != route2) {
if (route2.entry() == null || route2.entry() != exitSemaphore) { if (route2.entry() == null || route2.entry() != exitSemaphore) {
matches.add(new JastaddSemaphoreNeighborMatch(exitSemaphore, this, route2, sensor1, sensor2, te1, te2)); matches.add(new JastaddSemaphoreNeighborMatch(exitSemaphore, this, route2, sensor1, sensor2, te1, te2));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment