github.com/enbility/spine-go@v0.7.0/model/usecaseinformation_additions.go (about) 1 package model 2 3 import "sync" 4 5 var uciMux sync.Mutex 6 7 // UseCaseInformationDataType 8 9 // find the matching UseCaseSupport index for a UseCaseNameType 10 func (u *UseCaseInformationDataType) useCaseSupportIndex(useCaseName UseCaseNameType) (int, bool) { 11 // get the element with the same entity 12 for index, item := range u.UseCaseSupport { 13 if item.UseCaseName != nil && *item.UseCaseName == useCaseName { 14 return index, true 15 } 16 } 17 18 return -1, false 19 } 20 21 // add a new UseCaseSupportType 22 func (u *UseCaseInformationDataType) Add(useCase UseCaseSupportType) { 23 uciMux.Lock() 24 defer uciMux.Unlock() 25 26 if useCase.UseCaseName == nil { 27 return 28 } 29 30 // only add it if it does not exist yet 31 if index, ok := u.useCaseSupportIndex(*useCase.UseCaseName); ok { 32 // overwrite it instead 33 u.UseCaseSupport[index] = useCase 34 return 35 } 36 37 u.UseCaseSupport = append(u.UseCaseSupport, useCase) 38 } 39 40 // remove a UseCaseSupportType with a given UseCaseNameType 41 func (u *UseCaseInformationDataType) Remove(useCaseName UseCaseNameType) { 42 uciMux.Lock() 43 defer uciMux.Unlock() 44 45 var usecases []UseCaseSupportType 46 47 for _, item := range u.UseCaseSupport { 48 if item.UseCaseName != nil && *item.UseCaseName != useCaseName { 49 usecases = append(usecases, item) 50 } 51 } 52 53 u.UseCaseSupport = usecases 54 }