-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
server/src/main/scala/kpn/server/analyzer/engine/monitor/MonitorRouteNextRouteAnalyzer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package kpn.server.analyzer.engine.monitor | ||
|
||
import kpn.api.common.data.WayMember | ||
import kpn.server.analyzer.engine.analysis.route.RouteWay | ||
|
||
class MonitorRouteNextRouteAnalyzer { | ||
|
||
def analyze(nodeId: Long, wayMember: WayMember): Option[RouteWay] = { | ||
|
||
val connectingNodeIds = if (wayMember.role.contains("forward")) { | ||
Seq(wayMember.way.nodes.head.id) | ||
} | ||
else if (wayMember.role.contains("backward")) { | ||
Seq(wayMember.way.nodes.last.id) | ||
} | ||
else { | ||
Seq( | ||
wayMember.way.nodes.head.id, | ||
wayMember.way.nodes.last.id | ||
) | ||
} | ||
|
||
if (connectingNodeIds.contains(nodeId)) { | ||
if (nodeId == wayMember.way.nodes.head.id) { | ||
Some(RouteWay(wayMember.way)) | ||
} | ||
else if (nodeId == wayMember.way.nodes.last.id) { | ||
Some(RouteWay(wayMember.way, reversed = true)) | ||
} | ||
else { | ||
None | ||
} | ||
} | ||
else { | ||
None | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...src/test/scala/kpn/server/analyzer/engine/monitor/MonitorRouteNextRouteAnalyzerTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package kpn.server.analyzer.engine.monitor | ||
|
||
import kpn.api.common.data.WayMember | ||
import kpn.core.util.UnitTest | ||
|
||
class MonitorRouteNextRouteAnalyzerTest extends UnitTest { | ||
|
||
test("connection") { | ||
analyze( | ||
new MonitorRouteTestData() { | ||
memberWay(10, "", 1, 2) | ||
} | ||
).shouldMatchTo(Some(false)) | ||
} | ||
|
||
test("connection to way with forward role") { | ||
analyze( | ||
new MonitorRouteTestData() { | ||
memberWay(10, "forward", 1, 2) | ||
} | ||
).shouldMatchTo(Some(false)) | ||
} | ||
|
||
test("connection to way with backward role") { | ||
analyze( | ||
new MonitorRouteTestData() { | ||
memberWay(10, "backward", 2, 1) | ||
} | ||
).shouldMatchTo(Some(true)) | ||
} | ||
|
||
test("gap") { | ||
analyze( | ||
new MonitorRouteTestData() { | ||
memberWay(10, "", 2, 3) | ||
} | ||
).shouldMatchTo(None) | ||
} | ||
|
||
test("gap - way with role forward") { | ||
analyze( | ||
new MonitorRouteTestData() { | ||
memberWay(10, "forward", 2, 1) | ||
} | ||
).shouldMatchTo(None) | ||
} | ||
|
||
test("gap - way with role backward") { | ||
analyze( | ||
new MonitorRouteTestData() { | ||
memberWay(10, "backward", 1, 2) | ||
} | ||
).shouldMatchTo(None) | ||
} | ||
|
||
private def analyze(data: MonitorRouteTestData): Option[Boolean] = { | ||
val relation = data.relation | ||
val wayMember = relation.members.head match { | ||
case m: WayMember => m | ||
case _ => throw new IllegalStateException() | ||
} | ||
val routeWayOption = new MonitorRouteNextRouteAnalyzer().analyze(1, wayMember) | ||
routeWayOption.map(_.reversed) | ||
} | ||
} |