-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
group.go
81 lines (62 loc) · 1.4 KB
/
group.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
package engine
type Group interface {
HasTimestamp() bool
GetTimestamp() int64
GetValue(int) interface{}
WithoutTimestamp() Group
WithTimestamp(int64) Group
}
type NullGroup struct {
Group
}
var ALL_GROUP_IDENTIFIER Group = NullGroup{}
func (self NullGroup) HasTimestamp() bool {
return false
}
func (self NullGroup) GetTimestamp() int64 {
return 0
}
func (self NullGroup) GetValue(idx int) interface{} {
panic("invalid index")
}
func (self NullGroup) WithoutTimestamp() Group {
return self
}
func (self NullGroup) WithTimestamp(timestamp int64) Group {
return createGroup2(true, timestamp, self)
}
type Group2 struct {
hasTimestamp bool
value0 interface{}
value1 Group
}
func createGroup2(hasTimestamp bool, value0 interface{}, value1 Group) Group {
return Group2{hasTimestamp, value0, value1}
}
func (self Group2) HasTimestamp() bool {
return self.hasTimestamp
}
func (self Group2) GetTimestamp() int64 {
if self.hasTimestamp {
return self.value0.(int64)
}
return 0
}
func (self Group2) WithoutTimestamp() Group {
if self.hasTimestamp {
return self.value1
}
return self
}
func (self Group2) WithTimestamp(timestamp int64) Group {
if self.hasTimestamp {
panic("This group has timestamp already")
}
return createGroup2(true, timestamp, self)
}
func (self Group2) GetValue(idx int) interface{} {
if idx == 0 {
return self.value0
}
return self.value1.GetValue(idx - 1)
}