Search in sources :

Example 21 with BlockEntry

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

the class ReferencesLibrary method getReferenceAsBlockConfiguration.

public static BlockConfigurationEntry getReferenceAsBlockConfiguration(BlockConfigurationReference reference, TransitGraphDao dao) {
    AgencyAndId blockId = reference.getBlockId();
    int configurationIndex = reference.getConfigurationIndex();
    BlockEntry block = dao.getBlockEntryForId(blockId);
    if (block == null)
        throw new IllegalStateException("block does not exist: " + reference);
    return block.getConfigurations().get(configurationIndex);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)

Example 22 with BlockEntry

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

the class ReferencesLibrary method getBlockAsReference.

public static BlockConfigurationReference getBlockAsReference(BlockConfigurationEntry blockConfig) {
    BlockEntry block = blockConfig.getBlock();
    int configurationIndex = block.getConfigurations().indexOf(blockConfig);
    return new BlockConfigurationReference(block.getId(), configurationIndex);
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)

Example 23 with BlockEntry

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

the class ExtendedCalendarServiceImpl method determineAllServiceIds.

private Set<ServiceIdActivation> determineAllServiceIds() {
    Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
    for (BlockEntry block : _transitGraphDao.getAllBlocks()) {
        for (BlockConfigurationEntry blockConfig : block.getConfigurations()) {
            ServiceIdActivation serviceIds = blockConfig.getServiceIds();
            allServiceIds.add(serviceIds);
        }
    }
    return allServiceIds;
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) HashSet(java.util.HashSet)

Example 24 with BlockEntry

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

the class BlockCalendarServiceImpl method getBlockInstance.

/**
 **
 * {@link BlockCalendarService} Interface
 ***
 */
@Cacheable(isValueSerializable = false)
@Override
public BlockInstance getBlockInstance(AgencyAndId blockId, long serviceDate) {
    BlockEntry block = _transitGraphDao.getBlockEntryForId(blockId);
    if (block == null)
        throw new IllegalArgumentException("unknown block: " + blockId);
    List<BlockConfigurationEntry> configurations = block.getConfigurations();
    int index = 0;
    Date date = new Date(serviceDate);
    InstanceState state = new InstanceState(serviceDate);
    /**
     * See the specific contract for {@link BlockEntry#getConfigurations()}
     * about the sort order of configurations
     */
    for (BlockConfigurationEntry configuration : configurations) {
        if (allServiceIdsAreActiveForServiceDate(configuration, date)) {
            return new BlockInstance(configuration, state);
        }
        index++;
    }
    return null;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 25 with BlockEntry

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

the class BlockCalendarServiceImpl method getClosestActiveBlocks.

@Override
public List<BlockInstance> getClosestActiveBlocks(AgencyAndId blockId, long time) {
    Date timeAsDate = new Date(time);
    Min<BlockInstance> m = new Min<BlockInstance>();
    BlockEntry blockEntry = _transitGraphDao.getBlockEntryForId(blockId);
    for (BlockConfigurationEntry blockConfig : blockEntry.getConfigurations()) {
        List<Date> serviceDates = _calendarService.getDatesForServiceIdsAsOrderedList(blockConfig.getServiceIds());
        int index = index(Collections.binarySearch(serviceDates, timeAsDate));
        if (index > 0) {
            BlockInstance instance = new BlockInstance(blockConfig, serviceDates.get(index - 1).getTime());
            long delta = getTimeToBlockInstance(instance, time);
            m.add(delta, instance);
        }
        if (index < serviceDates.size()) {
            BlockInstance instance = new BlockInstance(blockConfig, serviceDates.get(index).getTime());
            long delta = getTimeToBlockInstance(instance, time);
            m.add(delta, instance);
        }
    }
    return m.getMinElements();
}
Also used : Min(org.onebusaway.collections.Min) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date)

Aggregations

BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)31 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)13 ArrayList (java.util.ArrayList)11 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 List (java.util.List)8 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)8 Test (org.junit.Test)7 Date (java.util.Date)6 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)6 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6 FactoryMap (org.onebusaway.collections.FactoryMap)5 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 Cacheable (org.onebusaway.container.cache.Cacheable)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 BlockLayoverIndex (org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex)3 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)3