forked from jellydator/ttlcache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evictionreason_enumer.go
49 lines (40 loc) · 1.33 KB
/
evictionreason_enumer.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
package ttl
import (
"fmt"
)
const evictionReasonName = "RemovedEvictedSizeExpiredClosed"
var evictionReasonIndex = [...]uint8{0, 7, 18, 25, 31}
func (i EvictionReason) String() string {
if i < 0 || i >= EvictionReason(len(evictionReasonIndex)-1) {
return fmt.Sprintf("EvictionReason(%d)", i)
}
return evictionReasonName[evictionReasonIndex[i]:evictionReasonIndex[i+1]]
}
var evictionReasonValues = []EvictionReason{0, 1, 2, 3}
var evictionReasonNameToValueMap = map[string]EvictionReason{
evictionReasonName[0:7]: 0,
evictionReasonName[7:18]: 1,
evictionReasonName[18:25]: 2,
evictionReasonName[25:31]: 3,
}
// EvictionReasonString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func EvictionReasonString(s string) (EvictionReason, error) {
if val, ok := evictionReasonNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to EvictionReason values", s)
}
// EvictionReasonValues returns all values of the enum
func EvictionReasonValues() []EvictionReason {
return evictionReasonValues
}
// IsAEvictionReason returns "true" if the value is listed in the enum definition. "false" otherwise
func (i EvictionReason) IsAEvictionReason() bool {
for _, v := range evictionReasonValues {
if i == v {
return true
}
}
return false
}