Kaynağa Gözat

ConditionList added

0x4a52466c696e74 3 ay önce
ebeveyn
işleme
6f846a6f80
1 değiştirilmiş dosya ile 27 ekleme ve 0 silme
  1. 27 0
      conditions.go

+ 27 - 0
conditions.go

@@ -60,3 +60,30 @@ type Condition struct {
 func (s *Condition) IsValid() bool {
 	return len(s.Field) > 0 && s.Logic.IsValid() && s.Operator.IsValid()
 }
+
+//////////////////////////////////////////////////////////////////////////////
+
+type ConditionList []*Condition
+
+func (s *ConditionList) FieldExists(name string) bool {
+	for _, v := range *s {
+		if v.Field == name {
+			return true
+		}
+	}
+	return false
+}
+
+func (s *ConditionList) FieldsRemove(toRemove []string) {
+	toRemoveMap := make(map[string]struct{})
+	for _, item := range toRemove {
+		toRemoveMap[item] = struct{}{}
+	}
+	var result ConditionList
+	for _, item := range *s {
+		if _, found := toRemoveMap[item.Field]; !found {
+			result = append(result, item)
+		}
+	}
+	*s = result
+}