An object of this class represents one location.
# - - - - - c l a s s L o c a t i o n - - - - -
class Location:
'''Represents one location (containing one or more stations).
Exports:
Location(locCode):
[ locCode is a location code as a string ->
return a new Location object with that code and
containing no stations ]
.locCode: [ as passed to constructor, uppercased, read-only ]
.addStation(station):
[ station is a Station object ->
if self has a station whose station code matches
a station in self ->
raise IOError
else ->
self := self with station added ]
.lookupStaCode(staCode):
[ staCode is a string ->
if staCode matches a station code in self, case
insensitive ->
return the Station with that station code
else -> raise KeyError ]
.__str__(self):
[ return a string representation of self ]
State/Invariants:
.staCodeMap:
[ a dictionary whose keys are the station codes in
self, uppercased, and each corresponding value is
the Station object having that station code ]
'''
The constructor uppercases and stores the location code,
then creates the empty .staCodeMap
dictionary.
# - - - L o c a t i o n . _ _ i n i t _ _ - - -
def __init__(self, locCode):
'''Constructor for Location
'''
self.locCode = locCode.upper()
self.staCodeMap = {}