forked from davyxu/tabtoy
/
sflist.go
63 lines (46 loc) · 1.05 KB
/
sflist.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
62
63
package filter
import (
"sort"
"github.com/davyxu/tabtoy/v2/model"
)
type structFieldResult struct {
key *model.FieldDescriptor
value string
}
type structFieldList struct {
data []*structFieldResult
}
func (self *structFieldList) Add(fd *model.FieldDescriptor, value string) {
self.data = append(self.data, &structFieldResult{
key: fd,
value: value,
})
}
func (self *structFieldList) Exists(fd *model.FieldDescriptor) bool {
for _, libfd := range self.data {
if libfd.key == fd {
return true
}
}
return false
}
func (self *structFieldList) Len() int {
return len(self.data)
}
func (self *structFieldList) Get(index int) *structFieldResult {
return self.data[index]
}
func (self *structFieldList) Swap(i, j int) {
self.data[i], self.data[j] = self.data[j], self.data[i]
}
func (self *structFieldList) Less(i, j int) bool {
a := self.data[i]
b := self.data[j]
return a.key.Order < b.key.Order
}
func (self *structFieldList) Sort() {
sort.Sort(self)
}
func newStructFieldList() *structFieldList {
return &structFieldList{}
}