private static void verifyInteriorStopsAreUnchanged(
        List<String> originalStopIds,
        List<PatternStop> newStops,
        int firstDifferentIndex,
        int lastDifferentIndex,
        boolean movedRight
    ) {
        //Stops mapped to list of stop IDs simply for easier viewing/comparison with original IDs while debugging with
        // breakpoints.
        List<String> newStopIds = newStops.stream().map(s -> s.stop_id).collect(Collectors.toList());
        // Determine the bounds of the region that should be identical between the two lists.
        int beginRegion = movedRight ? firstDifferentIndex : firstDifferentIndex + 1;
        int endRegion = movedRight ? lastDifferentIndex - 1 : lastDifferentIndex;
        for (int i = beginRegion; i <= endRegion; i++) {
            // Shift index when selecting stop from original list to account for displaced stop.
            int shiftedIndex = movedRight ? i + 1 : i - 1;
            String newStopId = newStopIds.get(i);
            String originalStopId = originalStopIds.get(shiftedIndex);
            if (!newStopId.equals(originalStopId)) {
                // If stop ID for new stop at the given index does not match the original stop ID, the order of at least
                // one stop within the changed region has been changed, which is illegal according to the rule enforcing
                // only a single addition, deletion, or transposition per update.
                throw new IllegalStateException(RECONCILE_STOPS_ERROR_MSG);
            }
        }
    }
private static void verifyInteriorStopsAreUnchanged(
        List<String> originalStopIds,
        List<PatternStop> newStops,
        int firstDifferentIndex,
        int lastDifferentIndex,
        boolean movedRight
    ) {
        
        
        List<String> newStopIds = newStops.stream().map(s -> s.stop_id).collect(Collectors.toList());
        
        int beginRegion = movedRight ? firstDifferentIndex : firstDifferentIndex + 1;
        int endRegion = movedRight ? lastDifferentIndex - 1 : lastDifferentIndex;
        for (int i = beginRegion; i <= endRegion; i++) {
            
            int shiftedIndex = movedRight ? i + 1 : i - 1;
            String newStopId = newStopIds.get(i);
            String originalStopId = originalStopIds.get(shiftedIndex);
            if (!newStopId.equals(originalStopId)) {
                
                
                
                throw new IllegalStateException(RECONCILE_STOPS_ERROR_MSG);
            }
        }
    }
private static void verifyInteriorStopsAreUnchanged ( List < String > originalStopIds , List < PatternStop > newStops , int firstDifferentIndex , int lastDifferentIndex , boolean movedRight ) { //Stops mapped to list of stop IDs simply for easier viewing/comparison with original IDs while debugging with // breakpoints. List < String > newStopIds = newStops . stream ( ) . map ( s -> s . stop_id ) . collect ( Collectors . toList ( ) ) ; // Determine the bounds of the region that should be identical between the two lists. int beginRegion = movedRight ? firstDifferentIndex : firstDifferentIndex + 1 ; int endRegion = movedRight ? lastDifferentIndex - 1 : lastDifferentIndex ; for ( int i = beginRegion ; i <= endRegion ; i ++ ) { // Shift index when selecting stop from original list to account for displaced stop. int shiftedIndex = movedRight ? i + 1 : i - 1 ; String newStopId = newStopIds . get ( i ) ; String originalStopId = originalStopIds . get ( shiftedIndex ) ; if ( ! newStopId . equals ( originalStopId ) ) { // If stop ID for new stop at the given index does not match the original stop ID, the order of at least // one stop within the changed region has been changed, which is illegal according to the rule enforcing // only a single addition, deletion, or transposition per update. throw new IllegalStateException ( RECONCILE_STOPS_ERROR_MSG ) ; } } }
Check the stops in the changed region to ensure they remain in the same order. If not, throw an exception to
cancel the transaction.
Check the stops in the changed region to ensure they remain in the same order . If not throw an exception to cancel the transaction .