-
Notifications
You must be signed in to change notification settings - Fork 18
/
result_mask.go
51 lines (41 loc) · 1.03 KB
/
result_mask.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
package floc
import (
"bytes"
"fmt"
)
// ResultMask is the mask of possible results.
type ResultMask Result
const emptyResultMask = ResultMask(0)
// EmptyResultMask returns empty result set.
func EmptyResultMask() ResultMask {
return emptyResultMask
}
// NewResultMask constructs new instance from the mask given.
func NewResultMask(mask Result) ResultMask {
return ResultMask(mask & usedBitsMask)
}
// IsMasked tests if the result is masked.
func (mask ResultMask) IsMasked(result Result) bool {
return mask&ResultMask(result) == ResultMask(result)
}
// IsEmpty returns true if no result is masked.
func (mask ResultMask) IsEmpty() bool {
return mask == 0
}
func (mask ResultMask) String() string {
buf := &bytes.Buffer{}
fmt.Fprint(buf, "[")
empty := true
for _, result := range []Result{None, Completed, Canceled, Failed} {
if mask.IsMasked(result) {
if empty {
fmt.Fprint(buf, result.String())
} else {
fmt.Fprint(buf, ",", result.String())
}
empty = false
}
}
fmt.Fprint(buf, "]")
return buf.String()
}