-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstate.go
52 lines (44 loc) · 1.16 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
package stateful
const (
// AllStates is a wildcard which represents all states in the state machine
AllStates = DefaultState("*")
)
type (
// State represents a state of a stateful object
State interface {
GetID() string
IsWildCard() bool
}
// States are a slice of State
States []State
// DefaultState is a string which should be used in every stateful object as the state
DefaultState string
)
// IsWildCard checks if the current state is a wildcard.
// So if the state stands for all possible states
func (ds DefaultState) IsWildCard() bool {
return ds == AllStates
}
// GetID returns the string representation of the DefaultState
func (ds DefaultState) GetID() string {
return string(ds)
}
// Contains search in States if the given state is inside the States.
// It compares with GetID
func (ss States) Contains(state State) bool {
for _, currentState := range ss {
if currentState.GetID() == state.GetID() {
return true
}
}
return false
}
// HasWildCard checks if there is a wildcard state inside of States
func (ss States) HasWildCard() bool {
for _, currentState := range ss {
if currentState.IsWildCard() {
return true
}
}
return false
}