public boolean addRoadSegments ( RoadPath segments , boolean autoConnectHalts , boolean enableLoopAutoBuild ) { if ( segments == null || segments . isEmpty ( ) ) { return false ; } BusItineraryHalt halt ; RoadSegment sgmt ; final Map < BusItineraryHalt , RoadSegment > haltMapping = new TreeMap <> ( ( obj1 , obj2 ) -> Integer . compare ( System . identityHashCode ( obj1 ) , System . identityHashCode ( obj2 ) ) ) ; final Iterator < BusItineraryHalt > haltIterator = this . validHalts . iterator ( ) ; while ( haltIterator . hasNext ( ) ) { halt = haltIterator . next ( ) ; sgmt = this . roadSegments . getRoadSegmentAt ( halt . getRoadSegmentIndex ( ) ) ; haltMapping . put ( halt , sgmt ) ; } final boolean isValidBefore = isValidPrimitive ( ) ; final RoadPath changedPath = this . roadSegments . addAndGetPath ( segments ) ; if ( changedPath != null ) { if ( enableLoopAutoBuild ) { autoLoop ( isValidBefore , changedPath , segments ) ; } int nIdx ; for ( final Entry < BusItineraryHalt , RoadSegment > entry : haltMapping . entrySet ( ) ) { halt = entry . getKey ( ) ; sgmt = entry . getValue ( ) ; nIdx = this . roadSegments . indexOf ( sgmt ) ; halt . setRoadSegmentIndex ( nIdx ) ; halt . checkPrimitiveValidity ( ) ; } final BusItineraryHalt [ ] tabV = new BusItineraryHalt [ this . validHalts . size ( ) ] ; this . validHalts . toArray ( tabV ) ; this . validHalts . clear ( ) ; for ( final BusItineraryHalt busHalt : tabV ) { assert busHalt != null && busHalt . isValidPrimitive ( ) ; ListUtil . addIfAbsent ( this . validHalts , VALID_HALT_COMPARATOR , busHalt ) ; } if ( this . roadNetwork == null ) { final RoadNetwork network = segments . getFirstSegment ( ) . getRoadNetwork ( ) ; this . roadNetwork = new WeakReference <> ( network ) ; network . addRoadNetworkListener ( this ) ; } fireShapeChanged ( new BusChangeEvent ( this , BusChangeEventType . SEGMENT_ADDED , segments . getLastSegment ( ) , this . roadSegments . indexOf ( segments . getLastSegment ( ) ) , "shape" , //$NON-NLS-1$ null , null ) ) ; // Try to connect the itinerary halts to // the road segments if ( autoConnectHalts ) { putInvalidHaltsOnRoads ( ) ; } else { checkPrimitiveValidity ( ) ; } return true ; } return false ; }
Add road segments inside the bus itinerary .