-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathattr.go
151 lines (127 loc) · 2.57 KB
/
attr.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package graphman
import (
"fmt"
"sort"
"strings"
)
type Attrs map[string]interface{}
func (a Attrs) Has(key string) bool {
_, found := a[key]
return found
}
func (a *Attrs) Merge(b Attrs) {
for k, v := range b {
(*a)[k] = v
}
}
func (a *Attrs) Del(key string) {
delete(*a, key)
}
func (a Attrs) IsEmpty() bool { return len(a) == 0 }
func (a Attrs) String() string {
if a == nil {
return invalidPlaceholder
}
if len(a) == 0 {
return "[]"
}
elems := []string{}
for key, val := range a {
valStr := fmt.Sprintf("%v", val)
if valStr != "" {
elems = append(elems, fmt.Sprintf("%s:%s", key, valStr))
}
}
sort.Strings(elems)
return fmt.Sprintf("[%s]", strings.Join(elems, ","))
}
func (a Attrs) SetTitle(title string) Attrs {
a["title"] = title
return a
}
func (a Attrs) GetTitle() string {
if attr, found := a["title"]; found {
return attr.(string)
}
return ""
}
func (a Attrs) getOrCreatePert() *PertAttrs {
if _, ok := a["pert"]; !ok {
a["pert"] = &PertAttrs{}
}
return a["pert"].(*PertAttrs)
}
func (a Attrs) SetPertUndefinedDependency() Attrs {
pert := a.getOrCreatePert()
pert.IsUndefinedDependency = true
return a
}
func (a Attrs) SetPertEstimates(opt, real, pess float64) Attrs {
pert := a.getOrCreatePert()
pert.Optimistic = opt
pert.Realistic = real
pert.Pessimistic = pess
pert.IsAction = true
pert.IsState = false
return a
}
func (a Attrs) SetPertState() Attrs {
pert := a.getOrCreatePert()
pert.IsAction = false
pert.IsState = true
return a
}
func (a Attrs) SetPertAction() Attrs {
pert := a.getOrCreatePert()
pert.IsAction = true
pert.IsState = false
return a
}
func (a Attrs) SetPertUntitled() Attrs {
pert := a.getOrCreatePert()
pert.IsUntitled = true
return a
}
func (a Attrs) SetPertZeroTimeActivity() Attrs {
pert := a.getOrCreatePert()
pert.IsZeroTimeActivity = true
return a
}
func (a Attrs) SetPertNonStandardGraph() Attrs {
pert := a.getOrCreatePert()
pert.IsNonStandardGraph = true
return a
}
func (a Attrs) GetPert() *PertAttrs {
if attr, found := a["pert"]; found {
return attr.(*PertAttrs)
}
return nil
}
func (a Attrs) Clone() Attrs {
newAttrs := Attrs{}
for k, v := range a {
newAttrs[k] = v
}
return newAttrs
}
func (a Attrs) SetColor(color string) Attrs {
a["color"] = color
return a
}
func (a Attrs) GetColor() string {
if attr, found := a["color"]; found {
return attr.(string)
}
return ""
}
func (a Attrs) GetComment() string {
if attr, found := a["comment"]; found {
return attr.(string)
}
return ""
}
func (a Attrs) SetComment(comment string) Attrs {
a["comment"] = comment
return a
}