-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperty.go
85 lines (64 loc) · 1.73 KB
/
property.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
package core
type PropertySource interface {
GetName() string
GetSource() interface{}
GetProperty(name string) interface{}
ContainsProperty(name string) bool
GetPropertyNames() []string
}
type PropertySources struct {
sources []PropertySource
}
func NewPropertySources() *PropertySources {
return &PropertySources{
sources: make([]PropertySource, 0),
}
}
func (o *PropertySources) Get(name string) (PropertySource, bool) {
for _, source := range o.sources {
if source != nil && source.GetName() == name {
return source, true
}
}
return nil, false
}
func (o *PropertySources) Add(propertySource PropertySource) {
o.RemoveIfPresent(propertySource)
o.sources = append(o.sources, propertySource)
}
func (o *PropertySources) Remove(name string) PropertySource {
source, index := o.findPropertySourceByName(name)
if index != -1 {
o.sources = append(o.sources[:index], o.sources[index+1:]...)
}
return source
}
func (o *PropertySources) Replace(name string, propertySource PropertySource) {
_, index := o.findPropertySourceByName(name)
if index != -1 {
o.sources[index] = propertySource
}
}
func (o *PropertySources) RemoveIfPresent(propertySource PropertySource) {
if propertySource == nil {
return
}
_, index := o.findPropertySourceByName(propertySource.GetName())
if index != -1 {
o.sources = append(o.sources[:index], o.sources[index+1:]...)
}
}
func (o *PropertySources) findPropertySourceByName(name string) (PropertySource, int) {
for index, source := range o.sources {
if source.GetName() == name {
return source, index
}
}
return nil, -1
}
func (o *PropertySources) GetSize() int {
return len(o.sources)
}
func (o *PropertySources) GetPropertyResources() []PropertySource {
return o.sources
}