-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
structure.go
66 lines (52 loc) · 1.08 KB
/
structure.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
64
65
66
package output
import (
"sort"
"strings"
)
type Root struct {
Elements []Element
}
type Element struct {
FullName string
Attributes []Attribute
Elements []Element
}
func (e Element) SortedElements() []Element {
sort.Slice(e.Elements, func(i, j int) bool {
return e.Elements[i].FullName < e.Elements[j].FullName
})
return e.Elements
}
func (e Element) SortedAttributes() []Attribute {
sort.Slice(e.Attributes, func(i, j int) bool {
return e.Attributes[i].FullName < e.Attributes[j].FullName
})
return e.Attributes
}
func (e Element) ShortName() string {
dots := strings.Split(e.FullName, ".")
return dots[len(dots)-1]
}
func (e Element) IsDefault() bool {
for _, i := range e.Elements {
if !i.IsDefault() {
return false
}
}
for _, i := range e.Attributes {
if !i.IsDefault {
return false
}
}
return true
}
type Attribute struct {
FullName string
IsDefault bool
AdditionalComment string
Value interface{}
}
func (a Attribute) ShortName() string {
dots := strings.Split(a.FullName, ".")
return dots[len(dots)-1]
}