src/main/java/com/conveyal/gtfs/PatternFinder.java
public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopById, SQLErrorStorage errorStorage) {
        // Make pattern ID one-based to avoid any JS type confusion between an ID of zero vs. null value.
        int nextPatternId = 1;
        // Create an in-memory list of Patterns because we will later rename them before inserting them into storage.
        Map<TripPatternKey, Pattern> patterns = new HashMap<>();
        // TODO assign patterns sequential small integer IDs (may include route)
        for (TripPatternKey key : tripsForPattern.keySet()) {
            Collection<Trip> trips = tripsForPattern.get(key);
            Pattern pattern = new Pattern(key.stops, trips, null);
            // Overwrite long UUID with sequential integer pattern ID
            pattern.pattern_id = Integer.toString(nextPatternId++);
            // FIXME: Should associated shapes be a single entry?
            pattern.associatedShapes = new HashSet<>();
            trips.stream().forEach(trip -> pattern.associatedShapes.add(trip.shape_id));
            if (pattern.associatedShapes.size() > 1 && errorStorage != null) {
                // Store an error if there is more than one shape per pattern. Note: error storage is null if called via
                // MapDB implementation.
                // TODO: Should shape ID be added to trip pattern key?
                errorStorage.storeError(NewGTFSError.forEntity(
                        pattern,
                        NewGTFSErrorType.MULTIPLE_SHAPES_FOR_PATTERN)
                            .setBadValue(pattern.associatedShapes.toString()));
            }
            patterns.put(key, pattern);
        }
        // Name patterns before storing in SQL database.
        renamePatterns(patterns.values(), stopById);
        LOG.info("Total patterns: {}", tripsForPattern.keySet().size());
        return patterns;
    }
public Map<TripPatternKey, Pattern> createPatternObjects(Map<String, Stop> stopById, SQLErrorStorage errorStorage) {
        // Make pattern ID one-based to avoid any JS type confusion between an ID of zero vs. null value.
        int nextPatternId = 1;
        // Create an in-memory list of Patterns because we will later rename them before inserting them into storage.
        Map<TripPatternKey, Pattern> patterns = new HashMap<>();
        // TODO assign patterns sequential small integer IDs (may include route)
        for (TripPatternKey key : tripsForPattern.keySet()) {
            Collection<Trip> trips = tripsForPattern.get(key);
            Pattern pattern = new Pattern(key.stops, trips, null);
            // Overwrite long UUID with sequential integer pattern ID
            pattern.pattern_id = Integer.toString(nextPatternId++);
            // FIXME: Should associated shapes be a single entry?
            pattern.associatedShapes = new HashSet<>();
            trips.stream().forEach(trip -> pattern.associatedShapes.add(trip.shape_id));
            if (pattern.associatedShapes.size() > 1 && errorStorage != null) {
                // Store an error if there is more than one shape per pattern. Note: error storage is null if called via
                // MapDB implementation.
                // TODO: Should shape ID be added to trip pattern key?
                errorStorage.storeError(NewGTFSError.forEntity(
                        pattern,
                        NewGTFSErrorType.MULTIPLE_SHAPES_FOR_PATTERN)
                            .setBadValue(pattern.associatedShapes.toString()));
            }
            patterns.put(key, pattern);
        }
        // Name patterns before storing in SQL database.
        renamePatterns(patterns.values(), stopById);
        LOG.info("Total patterns: {}", tripsForPattern.keySet().size());
        return patterns;
    }
public Map < TripPatternKey , Pattern > createPatternObjects ( Map < String , Stop > stopById , SQLErrorStorage errorStorage ) { // Make pattern ID one-based to avoid any JS type confusion between an ID of zero vs. null value. int nextPatternId = 1 ; // Create an in-memory list of Patterns because we will later rename them before inserting them into storage. Map < TripPatternKey , Pattern > patterns = new HashMap <> ( ) ; // TODO assign patterns sequential small integer IDs (may include route) for ( TripPatternKey key : tripsForPattern . keySet ( ) ) { Collection < Trip > trips = tripsForPattern . get ( key ) ; Pattern pattern = new Pattern ( key . stops , trips , null ) ; // Overwrite long UUID with sequential integer pattern ID pattern . pattern_id = Integer . toString ( nextPatternId ++ ) ; // FIXME: Should associated shapes be a single entry? pattern . associatedShapes = new HashSet <> ( ) ; trips . stream ( ) . forEach ( trip -> pattern . associatedShapes . add ( trip . shape_id ) ) ; if ( pattern . associatedShapes . size ( ) > 1 && errorStorage != null ) { // Store an error if there is more than one shape per pattern. Note: error storage is null if called via // MapDB implementation. // TODO: Should shape ID be added to trip pattern key? errorStorage . storeError ( NewGTFSError . forEntity ( pattern , NewGTFSErrorType . MULTIPLE_SHAPES_FOR_PATTERN ) . setBadValue ( pattern . associatedShapes . toString ( ) ) ) ; } patterns . put ( key , pattern ) ; } // Name patterns before storing in SQL database. renamePatterns ( patterns . values ( ) , stopById ) ; LOG . info ( "Total patterns: {}" , tripsForPattern . keySet ( ) . size ( ) ) ; return patterns ; }
Once all trips have been processed, call this method to produce the final Pattern objects representing all the
unique sequences of stops encountered. Returns map of patterns to their keys so that downstream functions can
make use of trip pattern keys for constructing pattern stops or other derivative objects.
Once all trips have been processed call this method to produce the final Pattern objects representing all the unique sequences of stops encountered . Returns map of patterns to their keys so that downstream functions can make use of trip pattern keys for constructing pattern stops or other derivative objects .