修改条件表达式的表达方式
This commit is contained in:
parent
ed4ddb00ed
commit
ed2dfe0809
|
@ -79,7 +79,7 @@ func TestParseIntervalPlus(t *testing.T) {
|
|||
|
||||
log.SetFlags(log.Llongfile)
|
||||
|
||||
crontab := "f2|f2>3|f3>4|1|s4>5"
|
||||
crontab := "f=2|f2>=3|f3>=4|1|s4>=5"
|
||||
cron := NewCrontab(crontab)
|
||||
|
||||
i := 0
|
||||
|
|
103
interval_base.go
103
interval_base.go
|
@ -1,6 +1,7 @@
|
|||
package crontab
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -38,6 +39,58 @@ func (rlr *NodeCount) Compare(v plist.INode) bool {
|
|||
return rlr.GetValue().(int) > v.GetValue().(int)
|
||||
}
|
||||
|
||||
func parseIntervalFail(interval *hInterval, FN string) {
|
||||
scharIndex := strings.Index(FN, ">")
|
||||
if scharIndex != -1 {
|
||||
|
||||
if FN[scharIndex+1] != '=' {
|
||||
panic(errors.New("= is not exist"))
|
||||
}
|
||||
|
||||
fc := FN[0:scharIndex]
|
||||
flr := FN[scharIndex+2:]
|
||||
|
||||
node := new(NodeCount)
|
||||
node.SetValue(getInt(fc[1:]))
|
||||
node.randLR = parseRandLR(flr)
|
||||
interval.PlanFailCount.Insert(node)
|
||||
} else {
|
||||
|
||||
if FN[1] != '=' {
|
||||
panic(errors.New("= is not exist"))
|
||||
}
|
||||
|
||||
fvalue := FN[2:]
|
||||
interval.PlanFail = append(interval.PlanFail, parseRandLR(fvalue))
|
||||
}
|
||||
}
|
||||
|
||||
func parseIntervalSuccess(interval *hInterval, FN string) {
|
||||
scharIndex := strings.Index(FN, ">")
|
||||
if scharIndex != -1 {
|
||||
if FN[scharIndex+1] != '=' {
|
||||
panic(errors.New("= is not exist"))
|
||||
}
|
||||
|
||||
tc := FN[0:scharIndex]
|
||||
tlr := FN[scharIndex+2:]
|
||||
|
||||
node := new(NodeCount)
|
||||
node.SetValue(getInt(tc[1:]))
|
||||
node.randLR = parseRandLR(tlr)
|
||||
interval.PlanTrueCount.Insert(node)
|
||||
|
||||
} else {
|
||||
|
||||
if FN[1] != '=' {
|
||||
panic(errors.New("= is not exist"))
|
||||
}
|
||||
|
||||
tvalue := FN[2:]
|
||||
interval.PlanTrue = append(interval.PlanTrue, parseRandLR(tvalue))
|
||||
}
|
||||
}
|
||||
|
||||
func parseIntervalString(crontab string) []interface{} {
|
||||
var result []interface{}
|
||||
|
||||
|
@ -73,54 +126,12 @@ func parseIntervalString(crontab string) []interface{} {
|
|||
|
||||
switch FN[0] {
|
||||
case 'f', 'F':
|
||||
scharIndex := strings.Index(FN, ">")
|
||||
if scharIndex != -1 {
|
||||
|
||||
fc := FN[0:scharIndex]
|
||||
flr := FN[scharIndex+1:]
|
||||
|
||||
node := new(NodeCount)
|
||||
node.SetValue(getInt(fc[1:]))
|
||||
node.randLR = parseRandLR(flr)
|
||||
interval.PlanFailCount.Insert(node)
|
||||
|
||||
} else {
|
||||
fvalue := FN[1:]
|
||||
interval.PlanFail = append(interval.PlanFail, parseRandLR(fvalue))
|
||||
}
|
||||
|
||||
parseIntervalFail(interval, FN)
|
||||
case 's', 'S':
|
||||
scharIndex := strings.Index(FN, ">")
|
||||
if scharIndex != -1 {
|
||||
tc := FN[0:scharIndex]
|
||||
tlr := FN[scharIndex+1:]
|
||||
|
||||
node := new(NodeCount)
|
||||
node.SetValue(getInt(tc[1:]))
|
||||
node.randLR = parseRandLR(tlr)
|
||||
interval.PlanTrueCount.Insert(node)
|
||||
|
||||
} else {
|
||||
tvalue := FN[1:]
|
||||
interval.PlanTrue = append(interval.PlanTrue, parseRandLR(tvalue))
|
||||
}
|
||||
|
||||
parseIntervalSuccess(interval, FN)
|
||||
default:
|
||||
FN = "s" + FN
|
||||
scharIndex := strings.Index(FN, ">")
|
||||
if scharIndex != -1 {
|
||||
tc := FN[0:scharIndex]
|
||||
tlr := FN[scharIndex+1:]
|
||||
|
||||
node := new(NodeCount)
|
||||
node.SetValue(getInt(tc[1:]))
|
||||
node.randLR = parseRandLR(tlr)
|
||||
interval.PlanTrueCount.Insert(node)
|
||||
|
||||
} else {
|
||||
tvalue := FN[1:]
|
||||
interval.PlanTrue = append(interval.PlanTrue, parseRandLR(tvalue))
|
||||
}
|
||||
FN = "s=" + FN
|
||||
parseIntervalSuccess(interval, FN)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user