better match filter

This commit is contained in:
Radu Ioan Fericean
2015-10-22 17:03:46 +03:00
parent 07647f765b
commit ec57a3e80c
2 changed files with 15 additions and 3 deletions

View File

@@ -84,9 +84,9 @@ func (b *Balance) MatchFilter(o *Balance) bool {
}
return (o.ExpirationDate.IsZero() || b.ExpirationDate.Equal(o.ExpirationDate)) &&
(o.Weight == 0 || b.Weight == o.Weight) &&
(len(o.DestinationIds) == 0 || b.DestinationIds.Equal(o.DestinationIds)) &&
(len(o.Directions) == 0 || b.Directions.Equal(o.Directions)) &&
(len(o.Categories) == 0 || b.Categories.Equal(o.Categories)) &&
(len(o.DestinationIds) == 0 || b.DestinationIds.Includes(o.DestinationIds)) &&
(len(o.Directions) == 0 || b.Directions.Includes(o.Directions)) &&
(len(o.Categories) == 0 || b.Categories.Includes(o.Categories)) &&
(o.RatingSubject == "" || b.RatingSubject == o.RatingSubject) &&
(o.SharedGroup == "" || b.SharedGroup == o.SharedGroup)
}

View File

@@ -97,6 +97,18 @@ func (sm StringMap) Equal(om StringMap) bool {
return true
}
func (sm StringMap) Includes(om StringMap) bool {
if len(sm) < len(om) {
return false
}
for key := range om {
if !sm[key] {
return false
}
}
return true
}
func (sm StringMap) Clone() StringMap {
result := make(StringMap, len(sm))
for k := range sm {