Search in sources :

Example 26 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class BlockTripIndexData method createIndex.

public BlockTripIndex createIndex(TransitGraphDao dao) {
    List<BlockTripEntry> trips = new ArrayList<BlockTripEntry>();
    for (BlockTripReference blockTripReference : _blockTripReferences) {
        BlockTripEntry trip = ReferencesLibrary.getReferenceAsTrip(blockTripReference, dao);
        trips.add(trip);
    }
    return new BlockTripIndex(trips, _serviceIntervalBlock);
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) ArrayList(java.util.ArrayList)

Example 27 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class BlockTripInstanceLibrary method getBlockTripInstance.

/**
 * Creates a {@link BlockTripInstance} from the specified
 * {@link BlockInstance} with the trip from the block matching the specified
 * tripId. If no trip is found in the block with the specified id, then null
 * is returned.
 *
 * Note that this is just a linear search. If this ends up being a performance
 * bottle-neck, we may have to look for a faster method here
 *
 * @param blockInstance
 * @param tripId
 * @return the new matching BlockTripInstance
 */
public static BlockTripInstance getBlockTripInstance(BlockInstance blockInstance, AgencyAndId tripId) {
    BlockConfigurationEntry blockConfig = blockInstance.getBlock();
    List<BlockTripEntry> blockTrips = blockConfig.getTrips();
    for (int i = 0; i < blockTrips.size(); ++i) {
        BlockTripEntry blockTrip = blockTrips.get(i);
        if (blockTrip.getTrip().getId().equals(tripId)) {
            return new BlockTripInstance(blockTrip, blockInstance.getState());
        }
    }
    return null;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 28 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class ReferencesLibrary method getReferenceAsTrip.

public static BlockTripEntry getReferenceAsTrip(BlockTripReference reference, TransitGraphDao dao) {
    BlockConfigurationEntry blockConfig = getReferenceAsBlockConfiguration(reference.getBlockConfigurationReference(), dao);
    List<BlockTripEntry> trips = blockConfig.getTrips();
    int tripIndex = reference.getTripIndex();
    return trips.get(tripIndex);
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 29 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImpl method getBlockStopTime.

private BlockStopTimeEntry getBlockStopTime(BlockTripInstance blockTripInstance, AgencyAndId stopId, int stopSequence, int timeOfServiceDate) {
    /**
     * We don't iterate over block stop times directly because there is
     * performance penalty with instantiating each. Also note that this will
     * currently miss the case where a stop is visited twice in the same trip.
     */
    BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
    TripEntry trip = blockTrip.getTrip();
    List<StopTimeEntry> stopTimes = trip.getStopTimes();
    if (stopSequence > -1) {
        /**
         * If a stop sequence has been specified, we start our search at the
         * specified index, expanding our search until we find the target stop. We
         * allow this flexibility in the case of a bookmarked arrival-departure
         * where the stop sequence has changed slightly due to the addition or
         * subtraction of a previous stop.
         */
        int offset = 0;
        while (true) {
            int before = stopSequence - offset;
            if (isMatch(stopTimes, stopId, before)) {
                return blockTrip.getStopTimes().get(before);
            }
            int after = stopSequence + offset;
            if (isMatch(stopTimes, stopId, after)) {
                return blockTrip.getStopTimes().get(after);
            }
            if (before < 0 && after >= stopTimes.size())
                return null;
            offset++;
        }
    } else {
        Min<BlockStopTimeEntry> m = new Min<BlockStopTimeEntry>();
        int index = 0;
        for (StopTimeEntry stopTime : stopTimes) {
            if (stopTime.getStop().getId().equals(stopId)) {
                int a = Math.abs(timeOfServiceDate - stopTime.getArrivalTime());
                int b = Math.abs(timeOfServiceDate - stopTime.getDepartureTime());
                int delta = Math.min(a, b);
                m.add(delta, blockTrip.getStopTimes().get(index));
            }
            index++;
        }
        if (m.isEmpty())
            return null;
        return m.getMinElement();
    }
}
Also used : Min(org.onebusaway.collections.Min) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 30 with BlockTripEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.

the class FrequencyEntriesFactory method computeBlockFrequencies.

private List<FrequencyEntry> computeBlockFrequencies(BlockEntryImpl block, List<BlockTripEntry> trips, Map<AgencyAndId, List<FrequencyEntry>> frequenciesAlongBlock) {
    List<FrequencyEntry> frequencies = null;
    for (BlockTripEntry blockTrip : trips) {
        TripEntry trip = blockTrip.getTrip();
        List<FrequencyEntry> potentialFrequencies = frequenciesAlongBlock.get(trip.getId());
        if (frequencies == null) {
            frequencies = potentialFrequencies;
        } else {
            if (!frequencies.equals(potentialFrequencies)) {
                throw new IllegalStateException("frequency-based trips in same block don't have same frequencies: blockId=" + block.getId());
            }
        }
    }
    return frequencies;
}
Also used : BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)

Aggregations

BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)72 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)30 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)27 ArrayList (java.util.ArrayList)26 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)25 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)23 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)15 List (java.util.List)11 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 FactoryMap (org.onebusaway.collections.FactoryMap)9 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)7 Date (java.util.Date)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceInterval (org.onebusaway.gtfs.model.calendar.ServiceInterval)5 StopSequence (org.onebusaway.transit_data_federation.model.StopSequence)5