-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specs.go
61 lines (52 loc) · 1.25 KB
/
specs.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
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Copyright © 2022-2023 Macaroni OS Linux
See AUTHORS and LICENSE for the license details and contributors.
*/
package specs
func NewCompilationspecs(s ...*CompilationSpec) *Compilationspecs {
all := Compilationspecs{}
for _, spec := range s {
all.Add(spec)
}
return &all
}
func (specs Compilationspecs) Len() int {
return len(specs)
}
func (specs *Compilationspecs) Remove(s *Compilationspecs) *Compilationspecs {
newSpecs := Compilationspecs{}
SPECS:
for _, spec := range specs.All() {
for _, target := range s.All() {
if target.GetPackage().Matches(spec.GetPackage()) {
continue SPECS
}
}
newSpecs.Add(spec)
}
return &newSpecs
}
func (specs *Compilationspecs) Add(s *CompilationSpec) {
*specs = append(*specs, *s)
}
func (specs *Compilationspecs) All() []*CompilationSpec {
var cspecs []*CompilationSpec
for i, _ := range *specs {
f := (*specs)[i]
cspecs = append(cspecs, &f)
}
return cspecs
}
func (specs *Compilationspecs) Unique() *Compilationspecs {
newSpecs := Compilationspecs{}
seen := map[string]bool{}
for i, _ := range *specs {
j := (*specs)[i]
_, ok := seen[j.GetPackage().GetFingerPrint()]
if !ok {
seen[j.GetPackage().GetFingerPrint()] = true
newSpecs = append(newSpecs, j)
}
}
return &newSpecs
}