Thanks to computer technology the functionality of phone systems has been greatly enhanced in the last ten years. We now have automated menus, sophisticated answering machines, conference call capabilities, group adressing and so on. A common feature of most current phone systems is the ability to set call forwaring. I somebody goes on vacation, he sets things up so that all incoming calls are forwarded to a colleague. Your task is to write a program that can be used to manage call forwarding at Ghent University.

All phones at Ghent University have four digit extensions. Employees can set call forwarding by entering the appropriate information through their telephone interface. If an employee is going to be away he enters the following information: his extension, the extension his calls should be forwarded to, the time he will be leaving, and how long he will be away. This information is subject to the following constraints:

The call forwarding system may assume that employees enter "correct" information, in the sense that they follow the formatting rules and they do not enter a request such that the duration of the request would go past the end of the year. The system must explicitly check if the same employee does not enter multiple requests that overlap in time. But even though employees enter correct, clear, non-overlapping information from their own point of view, inconsistencies can still occur in the call forwarding system if requests have been made in such a way as to forward a call back to the original target of the call. For example, if Bob forwards his calls to Sue, and Sue forwards her calls to Joe, and Joe forwards his calls to Bob. When somebody calls any of these three people their calls would be forwarded forever. To prevent this situation the call forwarding system uses the dead end phone extension 9999. Any calls made to an extension involved in such a degenerate situation will be forwarded to the special phone extension 9999.

Assignment

Define a class CallForwarding that can be used to operate a phone dispatching center that supports call forwarding. The functionality of the dispatching center must reflect the one described above. Objects of the class CallForwarding must therefore at least support the following methods:

Example

In the following interactive session we assume the current directory to contain the text file settings.txt1.

>>> dispatch = CallForwarding()
>>> dispatch.call('4444', 150)
'4444'
>>> dispatch.setForward('4444', '6666', 100, 200)
>>> dispatch.setForward('5555', '7777', 600, 200)
>>> dispatch.call('5555', 700)
'7777'
>>> dispatch.setForward('5555', '8888', 750, 100)
Traceback (most recent call last):
AssertionError: invalid forward

>>> dispatch2 = CallForwarding()
>>> dispatch2.setForwards('settings.txt')
>>> dispatch2.call('1111', 50)
'1111'
>>> dispatch2.call('1111', 150)
'2222'
>>> dispatch2.call('1111', 200)
'3333'
>>> dispatch2.call('2222', 225)
'3333'
>>> dispatch2.call('1111', 270)
'9999'
>>> dispatch2.call('1111', 320)
'4444'
>>> dispatch2.call('3333', 320)
'4444'
>>> dispatch2.call('3000', 900)
'3000'
>>> dispatch2.call('3333', 1250)
'1111'
>>> dispatch2.call('7777', 1250)
'9999'