1 /***********************************************************************
2  * Copyright (c) 2013-2024 Commonwealth Computer Research, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Apache License, Version 2.0
5  * which accompanies this distribution and is available at
6  * http://www.opensource.org/licenses/apache2.0.php. 
7  ***********************************************************************/
8 
9 package org.locationtech.geomesa.convert2.transforms
10 
11 import org.locationtech.geomesa.convert.EvaluationContext
12 import org.locationtech.geomesa.convert.EvaluationContext.ContextDependent
13 
14 sealed trait Predicate extends ContextDependent[Predicate] {
15   def apply(args: Array[AnyRef]): Boolean
16 }
17 
18 object Predicate {
19 
20   def apply(e: String): Predicate = PredicateParser.parse(e)
21 
22   case class BinaryEquals(left: Expression, right: Expression) extends Predicate {
23     override def apply(args: Array[AnyRef]): Boolean = left(args) == right(args)
24     override def withContext(ec: EvaluationContext): Predicate =
25       BinaryEquals(left.withContext(ec), right.withContext(ec))
26   }
27 
28   case class BinaryNotEquals(left: Expression, right: Expression) extends Predicate {
29     override def apply(args: Array[AnyRef]): Boolean = left(args) != right(args)
30     override def withContext(ec: EvaluationContext): Predicate =
31       BinaryNotEquals(left.withContext(ec), right.withContext(ec))
32   }
33 
34   case class BinaryLessThan(left: Expression, right: Expression) extends Predicate {
35     override def apply(args: Array[AnyRef]): Boolean =
36       left(args).asInstanceOf[Comparable[AnyRef]].compareTo(right(args)) < 0
37     override def withContext(ec: EvaluationContext): Predicate =
38       BinaryLessThan(left.withContext(ec), right.withContext(ec))
39   }
40 
41   case class BinaryLessThanOrEquals(left: Expression, right: Expression) extends Predicate {
42     override def apply(args: Array[AnyRef]): Boolean =
43       left(args).asInstanceOf[Comparable[AnyRef]].compareTo(right(args)) <= 0
44     override def withContext(ec: EvaluationContext): Predicate =
45       BinaryLessThanOrEquals(left.withContext(ec), right.withContext(ec))
46   }
47 
48   case class BinaryGreaterThan(left: Expression, right: Expression) extends Predicate {
49     override def apply(args: Array[AnyRef]): Boolean =
50       left(args).asInstanceOf[Comparable[AnyRef]].compareTo(right(args)) > 0
51     override def withContext(ec: EvaluationContext): Predicate =
52       BinaryGreaterThan(left.withContext(ec), right.withContext(ec))
53   }
54 
55   case class BinaryGreaterThanOrEquals(left: Expression, right: Expression) extends Predicate {
56     override def apply(args: Array[AnyRef]): Boolean =
57       left(args).asInstanceOf[Comparable[AnyRef]].compareTo(right(args)) >= 0
58     override def withContext(ec: EvaluationContext): Predicate =
59       BinaryGreaterThanOrEquals(left.withContext(ec), right.withContext(ec))
60   }
61 
62   case class And(clause: Predicate, clauses: Seq[Predicate]) extends Predicate {
63     override def apply(args: Array[AnyRef]): Boolean =
64       clause(args) && clauses.forall(_.apply(args))
65     override def withContext(ec: EvaluationContext): Predicate =
66       And(clause.withContext(ec), clauses.map(_.withContext(ec)))
67   }
68 
69   case class Or(clause: Predicate, clauses: Seq[Predicate])  extends Predicate {
70     override def apply(args: Array[AnyRef]): Boolean =
71       clause(args) || clauses.exists(_.apply(args))
72     override def withContext(ec: EvaluationContext): Predicate =
73       Or(clause.withContext(ec), clauses.map(_.withContext(ec)))
74   }
75 
76   case class Not(p: Predicate) extends Predicate {
77     override def apply(args: Array[AnyRef]): Boolean = !p(args)
78     override def withContext(ec: EvaluationContext): Predicate = Not(p.withContext(ec))
79   }
80 }
Line Stmt Id Pos Tree Symbol Tests Code
20 56635 816 - 840 Apply org.locationtech.geomesa.convert2.transforms.PredicateParser.parse PredicateParser.parse(e, PredicateParser.parse$default$2)
23 56636 994 - 1005 Apply org.locationtech.geomesa.convert2.transforms.Expression.apply BinaryEquals.this.right.apply(args)
23 56637 980 - 1005 Apply java.lang.Object.== BinaryEquals.this.left.apply(args).==(BinaryEquals.this.right.apply(args))
25 56638 1090 - 1110 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryEquals.this.left.withContext(ec)
25 56639 1112 - 1133 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryEquals.this.right.withContext(ec)
25 56640 1077 - 1134 Apply org.locationtech.geomesa.convert2.transforms.Predicate.BinaryEquals.apply Predicate.this.BinaryEquals.apply(BinaryEquals.this.left.withContext(ec), BinaryEquals.this.right.withContext(ec))
29 56641 1295 - 1306 Apply org.locationtech.geomesa.convert2.transforms.Expression.apply BinaryNotEquals.this.right.apply(args)
29 56642 1281 - 1306 Apply java.lang.Object.!= BinaryNotEquals.this.left.apply(args).!=(BinaryNotEquals.this.right.apply(args))
31 56643 1394 - 1414 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryNotEquals.this.left.withContext(ec)
31 56644 1416 - 1437 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryNotEquals.this.right.withContext(ec)
31 56645 1378 - 1438 Apply org.locationtech.geomesa.convert2.transforms.Predicate.BinaryNotEquals.apply Predicate.this.BinaryNotEquals.apply(BinaryNotEquals.this.left.withContext(ec), BinaryNotEquals.this.right.withContext(ec))
36 56646 1590 - 1660 Apply scala.Int.< BinaryLessThan.this.left.apply(args).asInstanceOf[Comparable[AnyRef]].compareTo(BinaryLessThan.this.right.apply(args)).<(0)
38 56647 1747 - 1767 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryLessThan.this.left.withContext(ec)
38 56648 1769 - 1790 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryLessThan.this.right.withContext(ec)
38 56649 1732 - 1791 Apply org.locationtech.geomesa.convert2.transforms.Predicate.BinaryLessThan.apply Predicate.this.BinaryLessThan.apply(BinaryLessThan.this.left.withContext(ec), BinaryLessThan.this.right.withContext(ec))
43 56650 1951 - 2022 Apply scala.Int.<= BinaryLessThanOrEquals.this.left.apply(args).asInstanceOf[Comparable[AnyRef]].compareTo(BinaryLessThanOrEquals.this.right.apply(args)).<=(0)
45 56651 2117 - 2137 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryLessThanOrEquals.this.left.withContext(ec)
45 56652 2139 - 2160 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryLessThanOrEquals.this.right.withContext(ec)
45 56653 2094 - 2161 Apply org.locationtech.geomesa.convert2.transforms.Predicate.BinaryLessThanOrEquals.apply Predicate.this.BinaryLessThanOrEquals.apply(BinaryLessThanOrEquals.this.left.withContext(ec), BinaryLessThanOrEquals.this.right.withContext(ec))
50 56654 2316 - 2386 Apply scala.Int.> BinaryGreaterThan.this.left.apply(args).asInstanceOf[Comparable[AnyRef]].compareTo(BinaryGreaterThan.this.right.apply(args)).>(0)
52 56655 2476 - 2496 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryGreaterThan.this.left.withContext(ec)
52 56656 2498 - 2519 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryGreaterThan.this.right.withContext(ec)
52 56657 2458 - 2520 Apply org.locationtech.geomesa.convert2.transforms.Predicate.BinaryGreaterThan.apply Predicate.this.BinaryGreaterThan.apply(BinaryGreaterThan.this.left.withContext(ec), BinaryGreaterThan.this.right.withContext(ec))
57 56658 2683 - 2754 Apply scala.Int.>= BinaryGreaterThanOrEquals.this.left.apply(args).asInstanceOf[Comparable[AnyRef]].compareTo(BinaryGreaterThanOrEquals.this.right.apply(args)).>=(0)
59 56659 2852 - 2872 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryGreaterThanOrEquals.this.left.withContext(ec)
59 56660 2874 - 2895 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext BinaryGreaterThanOrEquals.this.right.withContext(ec)
59 56661 2826 - 2896 Apply org.locationtech.geomesa.convert2.transforms.Predicate.BinaryGreaterThanOrEquals.apply Predicate.this.BinaryGreaterThanOrEquals.apply(BinaryGreaterThanOrEquals.this.left.withContext(ec), BinaryGreaterThanOrEquals.this.right.withContext(ec))
64 56662 3075 - 3088 Apply org.locationtech.geomesa.convert2.transforms.Predicate.apply x$1.apply(args)
64 56663 3060 - 3089 Apply scala.collection.IterableLike.forall And.this.clauses.forall(((x$1: org.locationtech.geomesa.convert2.transforms.Predicate) => x$1.apply(args)))
64 56664 3044 - 3089 Apply scala.Boolean.&& And.this.clause.apply(args).&&(And.this.clauses.forall(((x$1: org.locationtech.geomesa.convert2.transforms.Predicate) => x$1.apply(args))))
66 56665 3165 - 3187 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext And.this.clause.withContext(ec)
66 56666 3201 - 3218 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext x$2.withContext(ec)
66 56667 3200 - 3200 TypeApply scala.collection.Seq.canBuildFrom collection.this.Seq.canBuildFrom[org.locationtech.geomesa.convert2.transforms.Predicate]
66 56668 3189 - 3219 ApplyToImplicitArgs scala.collection.TraversableLike.map And.this.clauses.map[org.locationtech.geomesa.convert2.transforms.Predicate, Seq[org.locationtech.geomesa.convert2.transforms.Predicate]](((x$2: org.locationtech.geomesa.convert2.transforms.Predicate) => x$2.withContext(ec)))(collection.this.Seq.canBuildFrom[org.locationtech.geomesa.convert2.transforms.Predicate])
66 56669 3161 - 3220 Apply org.locationtech.geomesa.convert2.transforms.Predicate.And.apply Predicate.this.And.apply(And.this.clause.withContext(ec), And.this.clauses.map[org.locationtech.geomesa.convert2.transforms.Predicate, Seq[org.locationtech.geomesa.convert2.transforms.Predicate]](((x$2: org.locationtech.geomesa.convert2.transforms.Predicate) => x$2.withContext(ec)))(collection.this.Seq.canBuildFrom[org.locationtech.geomesa.convert2.transforms.Predicate]))
71 56670 3399 - 3412 Apply org.locationtech.geomesa.convert2.transforms.Predicate.apply x$3.apply(args)
71 56671 3384 - 3413 Apply scala.collection.IterableLike.exists Or.this.clauses.exists(((x$3: org.locationtech.geomesa.convert2.transforms.Predicate) => x$3.apply(args)))
71 56672 3368 - 3413 Apply scala.Boolean.|| Or.this.clause.apply(args).||(Or.this.clauses.exists(((x$3: org.locationtech.geomesa.convert2.transforms.Predicate) => x$3.apply(args))))
73 56673 3488 - 3510 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext Or.this.clause.withContext(ec)
73 56674 3524 - 3541 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext x$4.withContext(ec)
73 56675 3523 - 3523 TypeApply scala.collection.Seq.canBuildFrom collection.this.Seq.canBuildFrom[org.locationtech.geomesa.convert2.transforms.Predicate]
73 56676 3512 - 3542 ApplyToImplicitArgs scala.collection.TraversableLike.map Or.this.clauses.map[org.locationtech.geomesa.convert2.transforms.Predicate, Seq[org.locationtech.geomesa.convert2.transforms.Predicate]](((x$4: org.locationtech.geomesa.convert2.transforms.Predicate) => x$4.withContext(ec)))(collection.this.Seq.canBuildFrom[org.locationtech.geomesa.convert2.transforms.Predicate])
73 56677 3485 - 3543 Apply org.locationtech.geomesa.convert2.transforms.Predicate.Or.apply Predicate.this.Or.apply(Or.this.clause.withContext(ec), Or.this.clauses.map[org.locationtech.geomesa.convert2.transforms.Predicate, Seq[org.locationtech.geomesa.convert2.transforms.Predicate]](((x$4: org.locationtech.geomesa.convert2.transforms.Predicate) => x$4.withContext(ec)))(collection.this.Seq.canBuildFrom[org.locationtech.geomesa.convert2.transforms.Predicate]))
77 56678 3655 - 3663 Select scala.Boolean.unary_! Not.this.p.apply(args).unary_!
78 56679 3733 - 3750 Apply org.locationtech.geomesa.convert.EvaluationContext.ContextDependent.withContext Not.this.p.withContext(ec)
78 56680 3729 - 3751 Apply org.locationtech.geomesa.convert2.transforms.Predicate.Not.apply Predicate.this.Not.apply(Not.this.p.withContext(ec))