forked from steger/pr3-ws202526
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package airport
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type Airport struct {
|
|
Checkin Checkin
|
|
Security SecurityCheck
|
|
Gates map[GateNumber]*Gate
|
|
Runway Runway
|
|
Bhs *BaggageHandlingSystem
|
|
FlightSchedule FlightSchedule
|
|
}
|
|
|
|
func DefaultAirport() Airport {
|
|
|
|
ap := Airport{
|
|
Security: NewSecurityCheck(time.Duration(1 * time.Second)),
|
|
Gates: NewGates(10),
|
|
Runway: NewRunway(time.Duration(3 * time.Second)),
|
|
}
|
|
|
|
fs := GenerateRandomFlightSchedule(ap.Gates, 10)
|
|
ap.FlightSchedule = fs
|
|
|
|
baggageSinks := make(map[FlightNumber](BaggageProcessor))
|
|
for _, g := range ap.Gates {
|
|
|
|
var flightsForGate []Flight
|
|
for _, f := range fs.AllFlights() {
|
|
if f.GateNumber == g.id {
|
|
flightsForGate = append(flightsForGate, f)
|
|
}
|
|
baggageSinks[f.Id] = g
|
|
}
|
|
|
|
g.SetFlights(flightsForGate)
|
|
ap.Gates[g.id] = g
|
|
}
|
|
|
|
bhs := NewBaggageHandlingSystem(time.Duration(1*time.Second), baggageSinks)
|
|
ap.Bhs = &bhs
|
|
ap.Checkin = NewCheckin(time.Duration(1*time.Second), &fs, &bhs)
|
|
|
|
return ap
|
|
}
|
|
|
|
func (a *Airport) Start() {
|
|
go a.Checkin.Start()
|
|
go a.Security.Start()
|
|
go a.Bhs.Start()
|
|
go a.Runway.Start()
|
|
|
|
for _, g := range a.Gates {
|
|
go g.Start()
|
|
}
|
|
}
|
|
|
|
func (a *Airport) NewPassenger() Passenger {
|
|
return NewRandomPassenger(a.FlightSchedule.AllFlights())
|
|
}
|