forked from Jonathan-Rosenberg/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
string_list_diff.go
48 lines (36 loc) · 1.09 KB
/
string_list_diff.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package diff
import "github.com/treeverse/oasdiff/utils"
// StringsDiff describes the changes between a pair of lists of strings
type StringsDiff struct {
Added utils.StringList `json:"added,omitempty" yaml:"added,omitempty"`
Deleted utils.StringList `json:"deleted,omitempty" yaml:"deleted,omitempty"`
}
func newStringsDiff() *StringsDiff {
return &StringsDiff{
Added: utils.StringList{},
Deleted: utils.StringList{},
}
}
// Empty indicates whether a change was found in this element
func (stringsDiff *StringsDiff) Empty() bool {
if stringsDiff == nil {
return true
}
return len(stringsDiff.Added) == 0 &&
len(stringsDiff.Deleted) == 0
}
func getStringsDiff(strings1, strings2 utils.StringList) *StringsDiff {
diff := getStringsDiffInternal(strings1, strings2)
if diff.Empty() {
return nil
}
return diff
}
func getStringsDiffInternal(strings1, strings2 utils.StringList) *StringsDiff {
result := newStringsDiff()
s1 := strings1.ToStringSet()
s2 := strings2.ToStringSet()
result.Added = s2.Minus(s1).ToStringList()
result.Deleted = s1.Minus(s2).ToStringList()
return result
}