Skip to content

Commit 0b049b1

Browse files
committed
[core] Make constraints implement Stringer to make them printable
1 parent 1475bfc commit 0b049b1

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

core/task/constraint/constraints.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
package constraint
3030

3131
import (
32+
"fmt"
33+
"strings"
34+
3235
"github.com/AliceO2Group/Control/common/logger"
3336
"github.com/sirupsen/logrus"
3437
)
@@ -53,8 +56,34 @@ const (
5356
Equals Operator = 0
5457
)
5558

59+
func (o Operator) String() string {
60+
switch o {
61+
case Equals:
62+
return "EQUALS"
63+
}
64+
return ""
65+
}
66+
67+
func (c *Constraint) String() string {
68+
if c == nil {
69+
return ""
70+
}
71+
return fmt.Sprintf("ATTR:'%s' %s '%s'", c.Attribute, c.Operator.String(), c.Value)
72+
}
73+
5674
type Constraints []Constraint
5775

76+
func (cts Constraints) String() string {
77+
if cts == nil {
78+
return "[]"
79+
}
80+
strs := make([]string, len(cts))
81+
for i, ct := range cts {
82+
strs[i] = ct.String()
83+
}
84+
return fmt.Sprintf("[%s]", strings.Join(strs, ", "))
85+
}
86+
5887
func (cts Constraints) MergeParent(parentConstraints Constraints) (merged Constraints) {
5988
merged = make(Constraints, len(parentConstraints))
6089
copy(merged, parentConstraints)

0 commit comments

Comments
 (0)