public boolean removeRoadSegment ( int segmentIndex ) { if ( segmentIndex >= 0 && segmentIndex < this . roadSegments . getRoadSegmentCount ( ) ) { final RoadSegment segment = this . roadSegments . getRoadSegmentAt ( segmentIndex ) ; if ( segment != null ) { // // Invalidate the bus halts on the segment // final Map < BusItineraryHalt , RoadSegment > segmentMap = new TreeMap <> ( ( obj1 , obj2 ) -> Integer . compare ( System . identityHashCode ( obj1 ) , System . identityHashCode ( obj2 ) ) ) ; final Iterator < BusItineraryHalt > haltIterator = this . validHalts . iterator ( ) ; while ( haltIterator . hasNext ( ) ) { final BusItineraryHalt halt = haltIterator . next ( ) ; final int sgmtIndex = halt . getRoadSegmentIndex ( ) ; if ( sgmtIndex == segmentIndex ) { segmentMap . put ( halt , null ) ; } else { final RoadSegment sgmt = this . roadSegments . getRoadSegmentAt ( sgmtIndex ) ; segmentMap . put ( halt , sgmt ) ; } } // // Remove the road segment itself on the segment // this . roadSegments . removeRoadSegmentAt ( segmentIndex ) ; // // Force the road segment indexes // for ( final Entry < BusItineraryHalt , RoadSegment > entry : segmentMap . entrySet ( ) ) { final BusItineraryHalt halt = entry . getKey ( ) ; final RoadSegment sgmt = entry . getValue ( ) ; if ( sgmt == null ) { halt . setRoadSegmentIndex ( - 1 ) ; halt . setPositionOnSegment ( Float . NaN ) ; halt . checkPrimitiveValidity ( ) ; } else { final int sgmtIndex = halt . getRoadSegmentIndex ( ) ; final int idx = this . roadSegments . indexOf ( sgmt ) ; if ( idx != sgmtIndex ) { halt . setRoadSegmentIndex ( idx ) ; halt . checkPrimitiveValidity ( ) ; } } } // // Change the road network reference // if ( this . roadSegments . isEmpty ( ) && this . roadNetwork != null ) { final RoadNetwork network = this . roadNetwork . get ( ) ; if ( network != null ) { network . removeRoadNetworkListener ( this ) ; } this . roadNetwork = null ; } fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . SEGMENT_REMOVED , segment , segmentIndex , "shape" , //$NON-NLS-1$ null , null ) ) ; checkPrimitiveValidity ( ) ; return true ; } } return false ; }
Remove a road segment from this itinerary .