/
GreaterThanOrEqual.go
54 lines (45 loc) · 1.69 KB
/
GreaterThanOrEqual.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
52
53
54
// =================================================================
//
// Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================
package dfl
// GreaterThanOrEqual is a NumericBinaryOperator that evaluating to true if parameter a is greater than or equal to parameter b.
// The parameters may be of type int, int64, or float64.
type GreaterThanOrEqual struct {
*NumericBinaryOperator
}
func (gte GreaterThanOrEqual) Dfl(quotes []string, pretty bool, tabs int) string {
return gte.BinaryOperator.Dfl(">=", quotes, pretty, tabs)
}
// Sql returns the SQL representation of this node as a string
func (gte GreaterThanOrEqual) Sql(pretty bool, tabs int) string {
return gte.BinaryOperator.Sql(">=", pretty, tabs)
}
func (gte GreaterThanOrEqual) Map() map[string]interface{} {
return gte.BinaryOperator.Map(">=", gte.Left, gte.Right)
}
func (gte GreaterThanOrEqual) Compile() Node {
left := gte.Left.Compile()
right := gte.Right.Compile()
switch left.(type) {
case Literal:
switch right.(type) {
case Literal:
v, err := CompareNumbers(left.(Literal).Value, right.(Literal).Value)
if err != nil {
panic(err)
}
return Literal{Value: (v >= 0)}
}
}
return GreaterThanOrEqual{&NumericBinaryOperator{&BinaryOperator{Left: left, Right: right}}}
}
func (gte GreaterThanOrEqual) Evaluate(vars map[string]interface{}, ctx interface{}, funcs FunctionMap, quotes []string) (map[string]interface{}, interface{}, error) {
vars, v, err := gte.EvaluateAndCompare(vars, ctx, funcs, quotes)
if err != nil {
return vars, false, err
}
return vars, v >= 0, nil
}