This commit is contained in:
Timo Westkämper 2011-02-28 17:50:25 +00:00
parent bd2a65e947
commit 582cd7c022
2 changed files with 23 additions and 39 deletions

View File

@ -293,6 +293,8 @@ trait NumberExpression[T <: Number with Comparable[T]] extends ComparableExpress
def floor() = number[T](getType, MathOps.FLOOR, this);
def round() = number[T](getType, MathOps.ROUND, this);
def unary_-() = negate
private def castToNum[A <: Number with Comparable[A]](t: Class[A]): NumberExpression[A] = {
if (t.equals(getType)) {
@ -320,6 +322,8 @@ trait BooleanExpression extends ComparableExpression[java.lang.Boolean] with Pre
def not() = boolean(Ops.NOT, this);
def unary_! = not();
override def as(right: Path[java.lang.Boolean]) = boolean(ALIAS.asInstanceOf[Operator[java.lang.Boolean]], this, right);
override def as(alias: String): BooleanExpression = as(new PathImpl[java.lang.Boolean](getType, alias));
@ -418,37 +422,10 @@ trait StringExpression extends ComparableExpression[String] {
override def as(alias: String): StringExpression = as(new PathImpl[String](getType, alias));
def not() = new StringNegations(this)
// def not[F](func: (StringExpression) => F): F = func(this);
}
// NOTE : experimental
class StringNegations (val str: StringExpression) {
def like(right: String): BooleanExpression = str.like(right).not;
def like(right: Expression[String]) = str.like(right).not;
def matches(right: String) = str.matches(right).not;
def matches(right: Expression[String]) = str.matches(right).not;
def contains(right: String) = str.contains(right).not;
def contains(right: Expression[String]) = str.contains(right).not;
def startsWith(right: String) = str.startsWith(right).not;
def startsWith(right: Expression[String]) = str.startsWith(right).not;
def endsWith(right: String) = str.endsWith(right).not;
def endsWith(right: Expression[String]) = str.endsWith(right).not;
def empty = str.isNotEmpty;
}
trait TemporalExpression[T <: Comparable[_]] extends ComparableExpression[T] {
def after(right: T) = gt(right);

View File

@ -116,6 +116,11 @@ class ExpressionTest {
assertEquals("person.javaInt != 5", person.javaInt ne 5.asInstanceOf[Integer]); // FIXME
}
@Test
def Number_Negation {
assertEquals("person.scalaInt * -1", -person.scalaInt);
}
@Test
def Number_Comparison_With_Operators {
assertEquals("person.scalaInt < 5", person.scalaInt < 5);
@ -297,18 +302,20 @@ class ExpressionTest {
@Test
def String_Negations {
assertEquals("!person.firstName like XXX", person.firstName not() like "XXX"); // FIXME
assertEquals("!matches(person.firstName,XXX)", person.firstName not() matches "XXX"); // FIXME
assertEquals("!startsWith(person.firstName,XXX)", person.firstName not() startsWith"XXX"); // FIXME
assertEquals("!endsWith(person.firstName,XXX)", person.firstName not() endsWith "XXX"); // FIXME
assertEquals("!empty(person.firstName)", person.firstName not() empty); // FIXME
// assertEquals("!person.firstName like XXX", person.firstName not like "XXX"); // FIXME
// assertEquals("!matches(person.firstName,XXX)", person.firstName not matches("XXX")); // FIXME
// assertEquals("!startsWith(person.firstName,XXX)", person.firstName not startsWith("XXX")); // FIXME
// assertEquals("!endsWith(person.firstName,XXX)", person.firstName not endsWith("XXX")); // FIXME
// assertEquals("!empty(person.firstName)", person.firstName not empty); // FIXME
}
// @Test
// def Prefix(){
// assertEquals("count(person)", count(person));
// assertEquals("min(person.javaInt)", min(person.javaInt));
// assertEquals("min(person.scalaInt)", min(person.scalaInt));
// }
@Test
def String_Negations2 {
assertEquals("!person.firstName like XXX", !(person.firstName like "XXX"));
assertEquals("!matches(person.firstName,XXX)", !(person.firstName matches "XXX"));
assertEquals("!startsWith(person.firstName,XXX)", !(person.firstName startsWith "XXX"));
assertEquals("!endsWith(person.firstName,XXX)", !(person.firstName endsWith "XXX"));
assertEquals("!empty(person.firstName)", !(person.firstName isEmpty));
}
}