forked from steger/pr3-ws202627
Compare commits
No commits in common. "d1d2753280e7c688402a71763375d08516494a99" and "3492da5e5d628841bbc764caa841a6f42851d915" have entirely different histories.
d1d2753280
...
3492da5e5d
|
|
@ -1,8 +1,6 @@
|
||||||
package airport
|
package airport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -14,14 +12,6 @@ type BaggageHandlingSystem struct {
|
||||||
processingTime time.Duration
|
processingTime time.Duration
|
||||||
sinks map[FlightNumber]BaggageProcessor
|
sinks map[FlightNumber]BaggageProcessor
|
||||||
//TODO: extend
|
//TODO: extend
|
||||||
queue chan baggageData
|
|
||||||
list []LostBaggage
|
|
||||||
mu sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
type baggageData struct {
|
|
||||||
fn FlightNumber
|
|
||||||
b Baggage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type LostBaggage struct {
|
type LostBaggage struct {
|
||||||
|
|
@ -36,42 +26,19 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb
|
||||||
return BaggageHandlingSystem{
|
return BaggageHandlingSystem{
|
||||||
processingTime: processingTime,
|
processingTime: processingTime,
|
||||||
sinks: sinks,
|
sinks: sinks,
|
||||||
queue: make(chan baggageData),
|
|
||||||
list: make([]LostBaggage, 0),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
_, ok := bhs.sinks[fn]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Keine Flugnummer passend gefunden")
|
|
||||||
}
|
|
||||||
bhs.queue <- baggageData{fn: fn, b: b}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
bhs.mu.Lock()
|
return nil
|
||||||
verloren := bhs.list
|
|
||||||
bhs.list = make([]LostBaggage, 0)
|
|
||||||
bhs.mu.Unlock()
|
|
||||||
return verloren
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) Start() {
|
func (bhs *BaggageHandlingSystem) Start() {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
for element := range bhs.queue {
|
|
||||||
|
|
||||||
time.Sleep(bhs.processingTime)
|
|
||||||
sink := bhs.sinks[element.fn]
|
|
||||||
err := sink.ProcessBaggage(element.fn, element.b)
|
|
||||||
if err != nil {
|
|
||||||
bhs.mu.Lock()
|
|
||||||
bhs.list = append(bhs.list, LostBaggage{element.b, element.fn, err})
|
|
||||||
bhs.mu.Unlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
"gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaggageSpyData struct {
|
type BaggageSpyData struct {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
"gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FlightProviderStub struct {
|
type FlightProviderStub struct {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
"gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGateSingleFlight(t *testing.T) {
|
func TestGateSingleFlight(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package airport
|
package airport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -10,57 +9,17 @@ var prohibitedItems = map[string]bool{"Knife": true, "Gun": true, "Explosives":
|
||||||
type SecurityCheck struct {
|
type SecurityCheck struct {
|
||||||
processingTime time.Duration
|
processingTime time.Duration
|
||||||
//TODO: extend
|
//TODO: extend
|
||||||
queue chan passengerSecurityCheck
|
|
||||||
}
|
|
||||||
|
|
||||||
type passengerSecurityCheck struct {
|
|
||||||
p *Passenger
|
|
||||||
err chan error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSecurityCheck(processingTime time.Duration) SecurityCheck {
|
func NewSecurityCheck(processingTime time.Duration) SecurityCheck {
|
||||||
return SecurityCheck{
|
return SecurityCheck{
|
||||||
processingTime: processingTime,
|
processingTime: processingTime,
|
||||||
queue: make(chan passengerSecurityCheck),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func findProhibitedItem(items []string) (string, bool) {
|
|
||||||
for _, item := range items {
|
|
||||||
if prohibitedItems[item] {
|
|
||||||
return item, true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
|
|
||||||
// processes one passenger at a time. Each passenger must at least spend the processingTime at the security check
|
// processes one passenger at a time. Each passenger must at least spend the processingTime at the security check
|
||||||
func (sc *SecurityCheck) Start() {
|
func (sc *SecurityCheck) Start() {
|
||||||
for element := range sc.queue {
|
//TODO: implement
|
||||||
|
|
||||||
time.Sleep(sc.processingTime)
|
|
||||||
|
|
||||||
// Passagier hat keinen Boarding Pass (muss vor dem Namensvergleich kommen)
|
|
||||||
if element.p.BoardingPass == nil {
|
|
||||||
element.err <- fmt.Errorf("%s has no boarding pass", element.p.Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name stimmt nicht mit dem Boarding Pass überein
|
|
||||||
if element.p.Name != element.p.BoardingPass.Name {
|
|
||||||
element.err <- fmt.Errorf("name %s does not match boarding pass name %s", element.p.Name, element.p.BoardingPass.Name)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verbotener Gegenstand im Handgepäck
|
|
||||||
if item, found := findProhibitedItem(element.p.CarryOnItems); found {
|
|
||||||
element.err <- fmt.Errorf("%s carries prohibited item %s", element.p.Name, item)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Alles in Ordnung
|
|
||||||
element.err <- nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns an error if
|
// returns an error if
|
||||||
|
|
@ -68,7 +27,6 @@ func (sc *SecurityCheck) Start() {
|
||||||
// - the passenger's boardings pass does not match the name
|
// - the passenger's boardings pass does not match the name
|
||||||
// - the passenger carries a prohibited item
|
// - the passenger carries a prohibited item
|
||||||
func (sc SecurityCheck) Process(p Passenger) error {
|
func (sc SecurityCheck) Process(p Passenger) error {
|
||||||
err := make(chan error)
|
//TODO: implement
|
||||||
sc.queue <- passengerSecurityCheck{p: &p, err: err}
|
return nil
|
||||||
return <-err
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
"gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSecurityCheck(t *testing.T) {
|
func TestSecurityCheck(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
module gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport
|
module gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
"gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue