StandardRoadNetwork extends AbstractBoundedGISElement<GISContainer<?>, StandardRoadNetwork> implements RoadNetwork { @Override public boolean removeRoadSegment(RoadSegment segment) { if (segment == null) { return false; } if (this.roadSegments.remove(segment)) { if (segment instanceof RoadPolyline) { final RoadPolyline pl = (RoadPolyline) segment; pl.removeGISEditableChangeListener(this.eventHandler); pl.setStartPoint(null); pl.setEndPoint(null); pl.setRoadNetwork(null); } resetBoundingBox(); fireSegmentRemoved(segment); return true; } return false; } StandardRoadNetwork(Rectangle2afp<?, ?, ?, ?, ?, ?> originalBounds, AttributeCollection attributeProvider);  StandardRoadNetwork(Rectangle2afp<?, ?, ?, ?, ?, ?> originalBounds);  StandardRoadNetwork(UUID id, Rectangle2afp<?, ?, ?, ?, ?, ?> originalBounds, AttributeCollection attributeProvider);  StandardRoadNetwork(UUID id, Rectangle2afp<?, ?, ?, ?, ?, ?> originalBounds); @Override @Pure void toJson(JsonBuffer buffer); @Override @Pure StandardRoadNetwork clone(); @Pure GISPolylineSet<RoadPolyline> getInternalSet(); @SuppressWarnings("unchecked") @Pure Tree<RoadPolyline, ?> getInternalTree(); @Override final void setUUID(UUID id); @Pure LegalTrafficSide getLegalTrafficSide(); @Override @Pure @Inline(value = "getLegalTrafficSide() == $1.LEFT", imported = LegalTrafficSide.class) boolean isLeftSidedTrafficDirection(); @Override @Pure @Inline(value = "getLegalTrafficSide() == $1.RIGHT", imported = LegalTrafficSide.class) boolean isRightSidedTrafficDirection(); @Override @Pure int getSegmentCount(); @Override @Pure int getPointCount(); @Override @Pure boolean contains(Object obj); @Override @Pure final boolean contains(RoadSegment segment); @Override @Pure boolean isEmpty(); @Override Shape2d<?> getShape(); @Override @Pure GeoLocation getGeoLocation(); @Override @Pure Collection<? extends RoadSegment> getRoadSegments(); @Override @Pure final RoadSegment getRoadSegment(GeoId geoId); @Override @Pure final RoadSegment getRoadSegment(GeoLocation location); @Override @Pure Collection<RoadConnection> getConnections(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Override @Pure Collection<RoadConnection> getConnections(Rectangle2d bounds); @Override @Pure RoadConnection getNearestConnection(Point2D<?, ?> pos); @Override @Pure RoadSegment getNearestSegment(Point2D<?, ?> pos); @Override @Pure Pair<? extends RoadSegment, Double> getNearestSegmentData(Point2D<?, ?> pos); @Override @Pure Point1d getNearestPosition(Point2D<?, ?> pos); @Override @Pure Point1d getNearestPositionOnRoadBorder(Point2D<?, ?> pos); @Override final void addRoadSegment(RoadSegment segment); @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"}) final boolean addRoadPolyline(RoadPolyline segment); @Override boolean removeRoadSegment(RoadSegment segment); @Override boolean clear(); @Override final RoadConnection mergeRoadConnections(RoadConnection... connections); @Override @SuppressWarnings({"checkstyle:npathcomplexity"}) RoadConnection mergeRoadConnections(Collection<? extends RoadConnection> connections); @Override RoadConnection connectSegmentStartPoint(
			RoadConnection connection,
			RoadSegment segment,
			Point2D<?, ?> position); @Override RoadConnection connectSegmentEndPoint(
			RoadConnection connection,
			RoadSegment segment,
			Point2D<?, ?> position); @Override void addRoadNetworkListener(RoadNetworkListener listener); @Override void removeRoadNetworkListener(RoadNetworkListener listener); @Override @Pure GraphIterator<RoadSegment, RoadConnection> depthIterator(
			RoadSegment startingSegment, double depth,
			double position_from_starting_point, RoadConnection startingPoint,
			boolean allowManyReplies, boolean assumeOrientedSegments,
			DynamicDepthUpdater<RoadSegment, RoadConnection> dynamicDepthUpdater); @Override @Pure GraphIterator<RoadSegment, RoadConnection> iterator(
			RoadSegment starting_segment, RoadConnection starting_point,
			boolean allowManyReplies, boolean assumeOrientedSegments); @SuppressWarnings("unchecked") @Override @Pure Iterator<RoadSegment> iterator(); @Override @Pure Iterator<? extends RoadSegment> iterator(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Override @Pure Iterator<? extends RoadSegment> iterator(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds, int budget); @Override @Pure Iterable<? extends RoadSegment> toIterable(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds); @Override @Pure Iterable<? extends RoadSegment> toIterable(Rectangle2afp<?, ?, ?, ?, ?, ?> bounds, int budget); @Override @Pure Iterator<Rectangle2afp<?, ?, ?, ?, ?, ?>> boundsIterator();  }
@Test public void testRemoveRoadSegment() { assertTrue(this.network.removeRoadSegment(this.segment4)); assertTrue(this.network.removeRoadSegment(this.segment6)); assertEquals(7, this.network.getSegmentCount()); Collection<RoadSegmentStub> expectedList = new ArrayList<>(); Collections.addAll(expectedList, this.segment1, this.segment2, this.segment3, this.segment5, this.segment7, this.segment8, this.segment9); for(RoadSegment segment : this.network) { assertTrue(expectedList.contains(segment)); expectedList.remove(segment); } assertTrue(expectedList.isEmpty()); Collections.addAll(expectedList, this.segment1, this.segment2, this.segment3, this.segment5, this.segment7, this.segment8, this.segment9); for(RoadSegment segment : this.network.getRoadSegments()) { assertTrue(expectedList.contains(segment)); expectedList.remove(segment); } assertTrue(expectedList.isEmpty()); assertEquals(new Point2d(0.,0.), this.segment1.getFirstPoint()); assertEquals(this.segment1.getLastPoint(),this.segment2.getLastPoint()); assertEquals(this.segment2.getFirstPoint(),this.segment3.getFirstPoint()); assertEquals(this.segment2.getFirstPoint(),this.segment5.getFirstPoint()); assertEquals(this.segment2.getFirstPoint(),this.segment7.getFirstPoint()); assertEquals(this.segment2.getFirstPoint(),this.segment8.getLastPoint()); assertEquals(this.segment2.getFirstPoint(),this.segment9.getLastPoint()); assertEquals(this.segment2.getLastPoint(),this.segment1.getLastPoint()); assertEquals(this.segment3.getFirstPoint(),this.segment2.getFirstPoint()); assertEquals(this.segment3.getFirstPoint(),this.segment5.getFirstPoint()); assertEquals(this.segment3.getFirstPoint(),this.segment7.getFirstPoint()); assertEquals(this.segment3.getFirstPoint(),this.segment8.getLastPoint()); assertEquals(this.segment3.getFirstPoint(),this.segment9.getLastPoint()); assertEquals(new Point2d(-100.,-300), this.segment3.getLastPoint()); assertEquals(this.segment5.getFirstPoint(),this.segment2.getFirstPoint()); assertEquals(this.segment5.getFirstPoint(),this.segment3.getFirstPoint()); assertEquals(this.segment5.getFirstPoint(),this.segment7.getFirstPoint()); assertEquals(this.segment5.getFirstPoint(),this.segment8.getLastPoint()); assertEquals(this.segment5.getFirstPoint(),this.segment9.getLastPoint()); assertEquals(new Point2d(0.,10.), this.segment5.getLastPoint()); assertEquals(this.segment7.getFirstPoint(),this.segment2.getFirstPoint()); assertEquals(this.segment7.getFirstPoint(),this.segment3.getFirstPoint()); assertEquals(this.segment7.getFirstPoint(),this.segment5.getFirstPoint()); assertEquals(this.segment7.getFirstPoint(),this.segment8.getLastPoint()); assertEquals(this.segment7.getFirstPoint(),this.segment9.getLastPoint()); assertEquals(new Point2d(100.,-10.), this.segment7.getLastPoint()); assertEquals(new Point2d(170.,7.), this.segment8.getFirstPoint()); assertEquals(this.segment8.getLastPoint(),this.segment2.getFirstPoint()); assertEquals(this.segment8.getLastPoint(),this.segment3.getFirstPoint()); assertEquals(this.segment8.getLastPoint(),this.segment5.getFirstPoint()); assertEquals(this.segment8.getLastPoint(),this.segment7.getFirstPoint()); assertEquals(this.segment8.getLastPoint(),this.segment9.getLastPoint()); assertEquals(new Point2d(120.,100.), this.segment9.getFirstPoint()); assertEquals(this.segment9.getLastPoint(),this.segment2.getFirstPoint()); assertEquals(this.segment9.getLastPoint(),this.segment3.getFirstPoint()); assertEquals(this.segment9.getLastPoint(),this.segment5.getFirstPoint()); assertEquals(this.segment9.getLastPoint(),this.segment7.getFirstPoint()); assertEquals(this.segment9.getLastPoint(),this.segment8.getLastPoint()); assertFalse(this.network.removeRoadSegment(null)); assertFalse(this.network.removeRoadSegment(this.segment4)); }
@Test public void testConnectionIteratorAfterRemoval() { this.network.removeRoadSegment(this.segment4); this.network.removeRoadSegment(this.segment6); this.segment4 = this.segment6 = null; assumeTrue(CoordinateSystem2D.getDefaultCoordinateSystem().isRightHanded()); Iterator<RoadSegment> iterator = this.segment1.getBeginPoint().toCounterclockwiseIterator(this.segment1); assertTrue(iterator.hasNext()); assertEquals(this.segment1, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment1.getEndPoint().toCounterclockwiseIterator(this.segment1); assertTrue(iterator.hasNext()); assertEquals(this.segment1, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment2.getBeginPoint().toCounterclockwiseIterator(this.segment2); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment2.getEndPoint().toCounterclockwiseIterator(this.segment2); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment1, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment3.getBeginPoint().toCounterclockwiseIterator(this.segment3); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment3.getEndPoint().toCounterclockwiseIterator(this.segment3); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment5.getBeginPoint().toCounterclockwiseIterator(this.segment5); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment5.getEndPoint().toCounterclockwiseIterator(this.segment5); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment7.getBeginPoint().toCounterclockwiseIterator(this.segment7); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment7.getEndPoint().toCounterclockwiseIterator(this.segment7); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment8.getBeginPoint().toCounterclockwiseIterator(this.segment8); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment8.getEndPoint().toCounterclockwiseIterator(this.segment8); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment9.getBeginPoint().toCounterclockwiseIterator(this.segment9); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertFalse(iterator.hasNext()); iterator = this.segment9.getEndPoint().toCounterclockwiseIterator(this.segment9); assertTrue(iterator.hasNext()); assertEquals(this.segment9, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment2, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment5, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment3, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment7, iterator.next()); assertTrue(iterator.hasNext()); assertEquals(this.segment8, iterator.next()); assertFalse(iterator.hasNext()); }