修改条件表达式的表达方式

This commit is contained in:
eson 2018-12-22 04:04:12 +08:00
parent ed4ddb00ed
commit ed2dfe0809
2 changed files with 58 additions and 47 deletions

View File

@ -79,7 +79,7 @@ func TestParseIntervalPlus(t *testing.T) {
log.SetFlags(log.Llongfile) 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) cron := NewCrontab(crontab)
i := 0 i := 0

View File

@ -1,6 +1,7 @@
package crontab package crontab
import ( import (
"errors"
"strconv" "strconv"
"strings" "strings"
@ -38,6 +39,58 @@ func (rlr *NodeCount) Compare(v plist.INode) bool {
return rlr.GetValue().(int) > v.GetValue().(int) 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{} { func parseIntervalString(crontab string) []interface{} {
var result []interface{} var result []interface{}
@ -73,54 +126,12 @@ func parseIntervalString(crontab string) []interface{} {
switch FN[0] { switch FN[0] {
case 'f', 'F': case 'f', 'F':
scharIndex := strings.Index(FN, ">") parseIntervalFail(interval, 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))
}
case 's', 'S': case 's', 'S':
scharIndex := strings.Index(FN, ">") parseIntervalSuccess(interval, 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))
}
default: default:
FN = "s" + FN FN = "s=" + FN
scharIndex := strings.Index(FN, ">") parseIntervalSuccess(interval, 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))
}
} }
} }