-
Notifications
You must be signed in to change notification settings - Fork 22
/
state.go
66 lines (53 loc) · 1.31 KB
/
state.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 confirmation
const (
// Undefined is the default confirmation state.
Undefined State = iota
// Rejected is the state for rejected entities.
Rejected
// Pending is the state for pending entities.
Pending
// Accepted is the state for accepted entities.
Accepted
// Confirmed is the state for confirmed entities.
Confirmed
)
// State is the confirmation state of an entity.
type State uint8
// IsAccepted returns true if the state is Accepted or Confirmed.
func (s State) IsAccepted() bool {
return s >= Accepted
}
// IsConfirmed returns true if the state is Confirmed.
func (s State) IsConfirmed() bool {
return s >= Confirmed
}
// IsRejected returns true if the state is Rejected.
func (s State) IsRejected() bool {
return s == Rejected
}
// IsPending returns true if the state is Pending.
func (s State) IsPending() bool {
return s == Pending
}
// Aggregate returns the lowest confirmation state of all given states.
func (s State) Aggregate(o State) State {
if o < s {
return o
}
return s
}
// String returns a human-readable representation of the State.
func (s State) String() (humanReadable string) {
switch s {
case Pending:
return "Pending"
case Rejected:
return "Rejected"
case Accepted:
return "Accepted"
case Confirmed:
return "Confirmed"
default:
return "Undefined"
}
}