Connects a place to another one tht is specified in path If 'this place' is not in path an exception will be thrown @param path
(final Path path)
| 261 | * @param path |
| 262 | */ |
| 263 | public void connectPath(final Path path) throws RuntimeException, NullPointerException { |
| 264 | final Place[] pp = path.getPlaces(); |
| 265 | Place other; |
| 266 | |
| 267 | if (pp[0] == this) { |
| 268 | other = pp[1]; |
| 269 | } else if (pp[1] == this) { |
| 270 | other = pp[0]; |
| 271 | } else { |
| 272 | throw new RuntimeException("Wrong place in given path"); |
| 273 | } |
| 274 | |
| 275 | // check whether other place is null |
| 276 | if (other == null) { |
| 277 | throw new NullPointerException(); |
| 278 | } |
| 279 | |
| 280 | // check whether the path connects a place with itself on the same exit |
| 281 | if (other == this && path.getExitDirections()[0].equals(path.getExitDirections()[1])) { |
| 282 | throw new RuntimeException("Can not connect path to the same exit of one place"); |
| 283 | } |
| 284 | |
| 285 | paths.add(path); |
| 286 | other.paths.add(path); |
| 287 | |
| 288 | callWorldChangeListeners(); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Get a set of paths connected to exit |