-
Notifications
You must be signed in to change notification settings - Fork 77
/
tree.go
72 lines (61 loc) · 1.69 KB
/
tree.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
67
68
69
70
71
72
package domain
type (
// Tree domain model
Tree interface {
//Code - returns the idendifier of the category
Code() string
//Name - returns the name of the category
Name() string
//Path returns the Path as string
Path() string
//Active - should return true if the category is in the rootpath of the current category
Active() bool
//Subtrees returns a list of subtrees of the current node
SubTrees() []Tree
//HasChilds returns true if the node is no leaf node
HasChilds() bool
//DocumentCount - the amount of documents (products) in the category
DocumentCount() int
}
// TreeData defines the default domain tree data model
TreeData struct {
CategoryCode string
CategoryName string
CategoryPath string
CategoryDocumentCount int
SubTreesData []*TreeData
IsActive bool
}
)
// Active gets the node (category) active state
func (c TreeData) Active() bool {
return c.IsActive
}
// Code gets the category code represented by this node in the tree
func (c TreeData) Code() string {
return c.CategoryCode
}
// Name gets the category name
func (c TreeData) Name() string {
return c.CategoryName
}
// Path gets the Node (category) path
func (c TreeData) Path() string {
return c.CategoryPath
}
// DocumentCount gets the amount of documents in that node
func (c TreeData) DocumentCount() int {
return c.CategoryDocumentCount
}
// SubTrees gets the child Trees
func (c TreeData) SubTrees() []Tree {
result := make([]Tree, len(c.SubTreesData))
for i, child := range c.SubTreesData {
result[i] = Tree(child)
}
return result
}
// HasChilds - true if subTrees exist
func (c TreeData) HasChilds() bool {
return len(c.SubTreesData) > 0
}