use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method groupStopTimeInstancesByRouteCollectionId.
private void groupStopTimeInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
Map<AgencyAndId, Set<FrequencyEntry>> frequencyLabelsByRouteCollectionId = new FactoryMap<AgencyAndId, Set<FrequencyEntry>>(new HashSet<FrequencyEntry>());
for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) {
ServiceIdActivation serviceIds = index.getServiceIds();
Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
if (!serviceDates.contains(date))
continue;
Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
for (BlockStopTimeEntry stopTime : index.getStopTimes()) {
BlockTripEntry blockTrip = stopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
FrequencyEntry frequencyLabel = trip.getFrequencyLabel();
InstanceState state = new InstanceState(serviceDate.getTime(), frequencyLabel);
StopTimeInstance sti = new StopTimeInstance(stopTime, state);
if (frequencyLabel == null) {
stopTimesByRouteCollectionId.get(routeCollectionId).add(sti);
} else if (frequencyLabelsByRouteCollectionId.get(routeCollectionId).add(frequencyLabel)) {
frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
}
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method getServiceIdsByDate.
/**
**
* Private Methods
***
*/
private SortedMap<ServiceDate, Set<ServiceIdActivation>> getServiceIdsByDate(Set<ServiceIdActivation> allServiceIds) {
SortedMap<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = new TreeMap<ServiceDate, Set<ServiceIdActivation>>();
serviceIdsByDate = FactoryMap.createSorted(serviceIdsByDate, new HashSet<ServiceIdActivation>());
for (ServiceIdActivation serviceIds : allServiceIds) {
Set<ServiceDate> dates = _calendarService.getServiceDatesForServiceIds(serviceIds);
for (ServiceDate date : dates) {
serviceIdsByDate.get(date).add(serviceIds);
}
}
return serviceIdsByDate;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class BlockTripInstanceLibraryTest method test.
@Test
public void test() {
BlockEntryImpl block = UnitTestingSupport.block("block");
TripEntryImpl tripA = UnitTestingSupport.trip("tripA");
TripEntryImpl tripB = UnitTestingSupport.trip("tripB");
UnitTestingSupport.stopTime(0, null, tripA, 0, 0);
UnitTestingSupport.stopTime(0, null, tripB, 0, 0);
ServiceIdActivation serviceIds = UnitTestingSupport.serviceIds("sid");
BlockConfigurationEntry blockConfig = UnitTestingSupport.blockConfiguration(block, serviceIds, tripA, tripB);
BlockInstance blockInstanceA = new BlockInstance(blockConfig, 123L);
BlockTripInstance blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripA"));
assertSame(tripA, blockTripInstance.getBlockTrip().getTrip());
assertEquals(123L, blockTripInstance.getServiceDate());
blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripB"));
assertSame(tripB, blockTripInstance.getBlockTrip().getTrip());
assertEquals(123L, blockTripInstance.getServiceDate());
blockTripInstance = BlockTripInstanceLibrary.getBlockTripInstance(blockInstanceA, UnitTestingSupport.aid("tripC"));
assertNull(blockTripInstance);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds03.
@Test
public void testGetServiceDatesForServiceIds03() {
ServiceIdActivation serviceIds = serviceIds(lsids("sC", "sD"), lsids());
Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
assertEquals(1, dates.size());
assertTrue(dates.contains(new ServiceDate(2010, 9, 13).getAsDate(timeZone())));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImplTest method testGetPreviousServiceDatesForArrivalInterval.
@Test
public void testGetPreviousServiceDatesForArrivalInterval() {
BlockEntry blockA = block("blockA");
blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()));
List<BlockEntry> blocks = Arrays.asList(blockA);
Mockito.when(_transitGraphDao.getAllBlocks()).thenReturn(blocks);
_service.start();
ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids());
int inFrom = time(8, 00);
int inTo = time(20, 00);
ServiceInterval interval = new ServiceInterval(inFrom, inFrom, inTo, inTo);
long time = dateAsLong("2010-09-11 21:30");
List<Date> dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-11 00:00"), dates.get(0));
time = dateAsLong("2010-09-11 18:00");
dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-11 00:00"), dates.get(0));
time = dateAsLong("2010-09-11 07:00");
dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-10 00:00"), dates.get(0));
time = dateAsLong("2010-09-10 21:30");
dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-10 00:00"), dates.get(0));
time = dateAsLong("2010-09-10 18:00");
dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-10 00:00"), dates.get(0));
time = dateAsLong("2010-09-10 07:00");
dates = _service.getPreviousServiceDatesForArrivalInterval(serviceIds, interval, time);
assertEquals(0, dates.size());
}
Aggregations