org.onebusaway.gtfs.model.calendar.CalendarServiceData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of onebusaway-gtfs Show documentation
Show all versions of onebusaway-gtfs Show documentation
A Java library for reading and writing General Transit Feed Spec feeds
/**
* Copyright (C) 2011 Brian Ferris
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs.model.calendar;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import org.onebusaway.gtfs.model.AgencyAndId;
public class CalendarServiceData implements Serializable {
private static final long serialVersionUID = 1L;
private Map _timeZonesByAgencyId = new HashMap();
private Map> _serviceDatesByServiceId = new HashMap>();
private Map> _datesByLocalizedServiceId = new HashMap>();
private Map> _serviceIdsByDate = new HashMap>();
/**
* @param agencyId
* @return the time zone for the specified agencyId, or null if the agency was
* not found
*/
public TimeZone getTimeZoneForAgencyId(String agencyId) {
return _timeZonesByAgencyId.get(agencyId);
}
public void putTimeZoneForAgencyId(String agencyId, TimeZone timeZone) {
_timeZonesByAgencyId.put(agencyId, timeZone);
}
public Set getServiceIds() {
return Collections.unmodifiableSet(_serviceDatesByServiceId.keySet());
}
public Set getLocalizedServiceIds() {
return Collections.unmodifiableSet(_datesByLocalizedServiceId.keySet());
}
public List getServiceDatesForServiceId(AgencyAndId serviceId) {
return _serviceDatesByServiceId.get(serviceId);
}
public Set getServiceIdsForDate(ServiceDate date) {
Set serviceIds = _serviceIdsByDate.get(date);
if (serviceIds == null)
serviceIds = new HashSet();
return serviceIds;
}
public void putServiceDatesForServiceId(AgencyAndId serviceId,
List serviceDates) {
serviceDates = new ArrayList(serviceDates);
Collections.sort(serviceDates);
serviceDates = Collections.unmodifiableList(serviceDates);
_serviceDatesByServiceId.put(serviceId, serviceDates);
for (ServiceDate serviceDate : serviceDates) {
Set serviceIds = _serviceIdsByDate.get(serviceDate);
if (serviceIds == null) {
serviceIds = new HashSet();
_serviceIdsByDate.put(serviceDate, serviceIds);
}
serviceIds.add(serviceId);
}
}
public List getDatesForLocalizedServiceId(LocalizedServiceId serviceId) {
return _datesByLocalizedServiceId.get(serviceId);
}
public void putDatesForLocalizedServiceId(LocalizedServiceId serviceId,
List dates) {
dates = Collections.unmodifiableList(new ArrayList(dates));
_datesByLocalizedServiceId.put(serviceId, dates);
}
public void makeReadOnly() {
_timeZonesByAgencyId = Collections.unmodifiableMap(_timeZonesByAgencyId);
_serviceDatesByServiceId = Collections.unmodifiableMap(_serviceDatesByServiceId);
_datesByLocalizedServiceId = Collections.unmodifiableMap(_datesByLocalizedServiceId);
_serviceIdsByDate = Collections.unmodifiableMap(_serviceIdsByDate);
}
}