use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactory method processBlockConfigurations.
public void processBlockConfigurations(BlockEntryImpl block, List<TripEntryImpl> tripsInBlock) {
Map<LocalizedServiceId, List<TripEntryImpl>> tripsByServiceId = getTripsByServiceId(block, tripsInBlock);
List<ServiceIdActivation> combinations = _serviceIdOverlapCache.getOverlappingServiceIdCombinations(tripsByServiceId.keySet());
ArrayList<BlockConfigurationEntry> configurations = new ArrayList<BlockConfigurationEntry>();
for (ServiceIdActivation serviceIds : combinations) {
BlockConfigurationEntryImpl.Builder builder = processTripsForServiceIdConfiguration(block, tripsByServiceId, serviceIds);
configurations.add(builder.create());
}
Collections.sort(configurations, _blockConfigurationComparator);
configurations.trimToSize();
if (configurations.isEmpty())
_log.warn("no active block configurations found for block: " + block.getId());
block.setConfigurations(configurations);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class ServiceIdOverlapCache method computeCombinationsInternal.
private List<ServiceIdActivation> computeCombinationsInternal(Set<LocalizedServiceId> serviceIds) {
Map<ServiceDate, Set<LocalizedServiceId>> serviceIdsByServiceDate = new FactoryMap<ServiceDate, Set<LocalizedServiceId>>(new HashSet<LocalizedServiceId>());
for (LocalizedServiceId lsid : serviceIds) {
AgencyAndId serviceId = lsid.getId();
for (ServiceDate serviceDate : _calendarService.getServiceDatesForServiceId(serviceId)) serviceIdsByServiceDate.get(serviceDate).add(lsid);
}
Set<Set<LocalizedServiceId>> sets = new HashSet<Set<LocalizedServiceId>>();
sets.addAll(serviceIdsByServiceDate.values());
List<ServiceIdActivation> combinations = new ArrayList<ServiceIdActivation>();
for (Set<LocalizedServiceId> activeServiceIds : sets) {
Set<LocalizedServiceId> inactiveServiceIds = new HashSet<LocalizedServiceId>();
for (Set<LocalizedServiceId> combo2 : sets) {
if (isSubset(activeServiceIds, combo2))
inactiveServiceIds.addAll(combo2);
}
inactiveServiceIds.removeAll(activeServiceIds);
combinations.add(new ServiceIdActivation(list(activeServiceIds), list(inactiveServiceIds)));
}
Collections.sort(combinations);
return combinations;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds01.
@Test
public void testGetServiceDatesForServiceIds01() {
ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
assertEquals(1, dates.size());
assertTrue(dates.contains(new ServiceDate(2010, 9, 10).getAsDate(timeZone())));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds04.
@Test
public void testGetServiceDatesForServiceIds04() {
ServiceIdActivation serviceIds = serviceIds(lsids("sA", "sC"), lsids());
Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
assertEquals(0, dates.size());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImplTest method testGetNextServiceDatesForDepartureInterval.
@Test
public void testGetNextServiceDatesForDepartureInterval() {
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-10 09:30");
List<Date> dates = _service.getNextServiceDatesForDepartureInterval(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.getNextServiceDatesForDepartureInterval(serviceIds, interval, time);
assertEquals(1, dates.size());
assertEquals(date("2010-09-11 00:00"), dates.get(0));
time = dateAsLong("2010-09-11 21:30");
dates = _service.getNextServiceDatesForDepartureInterval(serviceIds, interval, time);
assertEquals(0, dates.size());
}
Aggregations