condition

package
v0.1.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: CC0-1.0, CC0-1.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	True  = Bool(true)
	False = Bool(false)
)

The possible truth valuations.

View Source
const (
	Eq = OpCode(iota) // Equal to (=)
	Ne                // Not equal to (!=)
	Gt                // Greater than (>)
	Lt                // Less than (<)
	Ge                // Greater than or equal to (>=)
	Le                // Less than or equal to (<=)
)

The valid OpCodes.

Variables

This section is empty.

Functions

This section is empty.

Types

type AndOp

type AndOp struct {
	// contains filtered or unexported fields
}

AndOp describes an AND operator.

func (*AndOp) Conditions

func (op *AndOp) Conditions() []Condition

Conditions returns the conditions that form the AND operator.

func (*AndOp) IsEqualTo

func (op *AndOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*AndOp) IsValid

func (op *AndOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*AndOp) Negate

func (op *AndOp) Negate() Condition

Negate returns the negation of the given operation.

func (*AndOp) Simplify

func (op *AndOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*AndOp) String

func (op *AndOp) String() string

String returns a string description of the operator.

type BetweenOp

type BetweenOp struct {
	// contains filtered or unexported fields
}

BetweenOp describes a BETWEEN operator.

func (*BetweenOp) IsEqualTo

func (op *BetweenOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*BetweenOp) IsValid

func (op *BetweenOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*BetweenOp) Lhs

func (op *BetweenOp) Lhs() string

Lhs returns the lhs of the operator.

func (*BetweenOp) Lower

func (op *BetweenOp) Lower() interface{}

Lower returns the lower value for of the operator.

func (*BetweenOp) Negate

func (op *BetweenOp) Negate() Condition

Negate returns the negation of the given operation.

func (*BetweenOp) Simplify

func (op *BetweenOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*BetweenOp) String

func (op *BetweenOp) String() string

String returns a string description of the operator.

func (*BetweenOp) Upper

func (op *BetweenOp) Upper() interface{}

Upper returns the upper value for of the operator.

type Bool

type Bool bool

Bool defines a truth valuation.

func (Bool) IsEqualTo

func (b Bool) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (Bool) IsValid

func (b Bool) IsValid() (bool, error)

IsValid always returns true, nil.

func (Bool) Negate

func (b Bool) Negate() Condition

Negate returns the negation of the given operation.

func (Bool) Simplify

func (b Bool) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (Bool) String

func (b Bool) String() string

String returns a string representation of the Bool.

type Condition

type Condition interface {
	// IsValid returns true iff the condition validates. If false, also
	// returns an error describing why validation failed.
	IsValid() (bool, error)
	// Negate returns the negation of the given operation.
	Negate() Condition
	// Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp,
	// and *OrOp conditions only.
	Simplify() Condition
	// IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).
	IsEqualTo(Condition) bool
}

Condition is the interface satisfied by a logical condition. Conditions produced by this package will be of one of the following types:

Bool
*LeafOp
*IsOp
*InOp
*NotInOp
*BetweenOp
*NotBetweenOp
*AndOp
*OrOp

func And

func And(cond ...Condition) Condition

And returns a new AND operator as an *AndOp or equivalent Condition. That is, it is equivalent to:

cond1 AND cond2 AND ... AND condN.

If no conditions are provided then this equivalent to the True valuation.

func Between

func Between(lhs string, lower interface{}, upper interface{}) Condition

Between returns a new BETWEEN operator as a *BetweenOp or equivalent Condition. The BETWEEN operator can be used to match against a range of values and is equivalent to:

lhs >= lower AND lhs <= upper.

func Equal

func Equal(lhs string, rhs interface{}) Condition

Equal returns the operator "lhs = rhs" (or its equivalent) as a *LeafOp.

func FromRecord

func FromRecord(r record.Record) Condition

FromRecord converts a record to a condition.

func GreaterThan

func GreaterThan(lhs string, rhs interface{}) Condition

GreaterThan returns the operator "lhs > rhs" (or its equivalent) as a *LeafOp.

func GreaterThanOrEqualTo

func GreaterThanOrEqualTo(lhs string, rhs interface{}) Condition

GreaterThanOrEqualTo returns the operator "lhs >= rhs" (or its equivalent) as a *LeafOp.

func In

func In(lhs string, value ...interface{}) Condition

In returns a new IN operator as an *InOp or equivalent Condition. The IN operator can be used to match a value against a list of values and is equivalent to successive OR operators:

lhs = value1 OR lhs = value2 OR ... OR lhs = valueN

If no values are provided then this equivalent to the False valuation.

func Is

func Is(lhs string, value bool) Condition

Is returns a new IS operator as an *IsOp. The IS operator can be used to match a value against a boolean value only.

func IsFalse

func IsFalse(lhs string) Condition

IsFalse returns the operator "lhs IS False" (or its equivalent) as a *IsOp.

func IsTrue

func IsTrue(lhs string) Condition

IsTrue returns the operator "lhs IS True" (or its equivalent) as a *IsOp.

func LessThan

func LessThan(lhs string, rhs interface{}) Condition

LessThan returns the operator "lhs < rhs" (or its equivalent) as a *LeafOp.

func LessThanOrEqualTo

func LessThanOrEqualTo(lhs string, rhs interface{}) Condition

LessThanOrEqualTo returns the operator "lhs <= rhs" (or its equivalent) as a *LeafOp.

func NotBetween

func NotBetween(lhs string, lower interface{}, upper interface{}) Condition

NotBetween returns a new NOT BETWEEN operator as a *NotBetweenOp or equivalent Condition. The NOT BETWEEN operator can be used to match against a range of values and is equivalent to:

lhs < lower OR lhs > upper.

func NotEqual

func NotEqual(lhs string, rhs interface{}) Condition

NotEqual returns the operator "lhs != rhs" (or its equivalent) as a *LeafOp.

func NotIn

func NotIn(lhs string, value ...interface{}) Condition

NotIn returns a new NOT IN operator as a *NotInOp or equivalent Condition. The NOT IN operator can be used to match a value against a list of values and is equivalent to successive AND operators:

lhs != value1 AND lhs != value2 AND ... AND lhs != valueN

If no values are provided then this equivalent to the True valuation.

func Or

func Or(cond ...Condition) Condition

Or returns a new OR operator as an *OrOp or equivalent Condition. That is, it is equivalent to:

cond1 OR cond2 OR ... OR condN.

If no conditions are provided then this equivalent to the False valuation.

type InOp

type InOp struct {
	// contains filtered or unexported fields
}

InOp describes an IN operator.

func (*InOp) IsEqualTo

func (op *InOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*InOp) IsValid

func (op *InOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*InOp) Lhs

func (op *InOp) Lhs() string

Lhs returns the lhs of the operator.

func (*InOp) Negate

func (op *InOp) Negate() Condition

Negate returns the negation of the given operation.

func (*InOp) Simplify

func (op *InOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*InOp) String

func (op *InOp) String() string

String returns a string description of the operator.

func (*InOp) Values

func (op *InOp) Values() []interface{}

Values returns the list of values for the operator.

type IsOp

type IsOp struct {
	// contains filtered or unexported fields
}

IsOp describes an IS operator.

func (*IsOp) IsEqualTo

func (op *IsOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*IsOp) IsValid

func (op *IsOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*IsOp) Lhs

func (op *IsOp) Lhs() string

Lhs returns the lhs of the operator.

func (*IsOp) Negate

func (op *IsOp) Negate() Condition

Negate returns the negation of the given operation.

func (*IsOp) Simplify

func (op *IsOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*IsOp) String

func (op *IsOp) String() string

String returns a string description of the operator.

func (*IsOp) Value

func (op *IsOp) Value() bool

Values returns the rhs of the operator.

type LeafOp

type LeafOp struct {
	// contains filtered or unexported fields
}

LeafOp describes an operator of the form "lhs op rhs" where "lhs" is given by a key, "op" is a valid OpCode, and "rhs" is a value.

func (*LeafOp) IsEqualTo

func (op *LeafOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*LeafOp) IsValid

func (op *LeafOp) IsValid() (bool, error)

IsValid returns true iff the operator validates. If false, also returns an error describing why validation failed.

func (*LeafOp) Lhs

func (op *LeafOp) Lhs() string

Lhs returns the lhs of the operator.

func (*LeafOp) Negate

func (op *LeafOp) Negate() Condition

Negate returns the negation of the given operation.

func (*LeafOp) OpCode

func (op *LeafOp) OpCode() OpCode

OpCode returns the OpCode of the operator.

func (*LeafOp) Rhs

func (op *LeafOp) Rhs() interface{}

Rhs returns the rhs of the operator.

func (*LeafOp) Simplify

func (op *LeafOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*LeafOp) String

func (op *LeafOp) String() string

String returns a string description of the operator.

type NotBetweenOp

type NotBetweenOp struct {
	// contains filtered or unexported fields
}

NotBetweenOp describes a NOT BETWEEN operator.

func (*NotBetweenOp) IsEqualTo

func (op *NotBetweenOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*NotBetweenOp) IsValid

func (op *NotBetweenOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*NotBetweenOp) Lhs

func (op *NotBetweenOp) Lhs() string

Lhs returns the lhs of the operator.

func (*NotBetweenOp) Lower

func (op *NotBetweenOp) Lower() interface{}

Lower returns the lower value for of the operator.

func (*NotBetweenOp) Negate

func (op *NotBetweenOp) Negate() Condition

Negate returns the negation of the given operation.

func (*NotBetweenOp) Simplify

func (op *NotBetweenOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*NotBetweenOp) String

func (op *NotBetweenOp) String() string

String returns a string description of the operator.

func (*NotBetweenOp) Upper

func (op *NotBetweenOp) Upper() interface{}

Upper returns the upper value for of the operator.

type NotInOp

type NotInOp struct {
	// contains filtered or unexported fields
}

NotInOp describes a NOT IN operator.

func (*NotInOp) IsEqualTo

func (op *NotInOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*NotInOp) IsValid

func (op *NotInOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*NotInOp) Lhs

func (op *NotInOp) Lhs() string

Lhs returns the lhs of the operator.

func (*NotInOp) Negate

func (op *NotInOp) Negate() Condition

Negate returns the negation of the given operation.

func (*NotInOp) Simplify

func (op *NotInOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*NotInOp) String

func (op *NotInOp) String() string

String returns a string description of the operator.

func (*NotInOp) Values

func (op *NotInOp) Values() []interface{}

Values returns the list of values for the operator.

type OpCode

type OpCode int

OpCode describes a binary operator.

func (OpCode) IsValid

func (c OpCode) IsValid() bool

IsValid returns true iff the OpCode is valid.

func (OpCode) String

func (c OpCode) String() string

String returns a string representation of the OpCode.

type OrOp

type OrOp struct {
	// contains filtered or unexported fields
}

OrOp describes an OR operator.

func (*OrOp) Conditions

func (op *OrOp) Conditions() []Condition

Conditions returns the conditions that form the OR operator.

func (*OrOp) IsEqualTo

func (op *OrOp) IsEqualTo(x Condition) bool

IsEqualTo returns true iff the conditions are equal (note that this does not check for equivalence).

func (*OrOp) IsValid

func (op *OrOp) IsValid() (bool, error)

IsValid returns true iff the condition validates. If false, also returns an error describing why validation failed.

func (*OrOp) Negate

func (op *OrOp) Negate() Condition

Negate returns the negation of the given operation.

func (*OrOp) Simplify

func (op *OrOp) Simplify() Condition

Simplify re-expresses the operator in terms of Bool, *LeafOp, *AndOp, and *OrOp conditions only.

func (*OrOp) String

func (op *OrOp) String() string

String returns a string description of the operator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL