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);
}
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);
}
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;
}
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;
}
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();
}
Aggregations