From f629b267ba2ff500f6eb219b9130a7d65815a0c9 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 9 Dec 2010 00:21:44 +0000 Subject: [PATCH] I'd like to be able to require that you at least can only call greatest and least on something that was Comparable, but unfortunately, the numeric type's only shared supertype is Number and that is not comparable. If I require Number, then you can't do greatest(timestamp, timestamp), and if I require Comparable, then you can't do greatest(int, double) because the compiler can't unify those types to something that is Comparable. I could require that you only compare apples with apples (i.e. greatest(int, int) or greatest(double, double)), but databases will happily compare greatest(int, double) and people are going to want to do that. I could introduce some sort of numeric conversion expressions, but I think that's getting too deeply into the realm of type safety for type safety's sake. --- src/main/java/com/samskivert/depot/Funcs.java | 12 ++++++------ .../depot/impl/expression/ConditionalFun.java | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/samskivert/depot/Funcs.java b/src/main/java/com/samskivert/depot/Funcs.java index 1333318..0ca46e3 100644 --- a/src/main/java/com/samskivert/depot/Funcs.java +++ b/src/main/java/com/samskivert/depot/Funcs.java @@ -127,8 +127,8 @@ public class Funcs /** * Creates an expression that evaluates to the largest of the given expressions. */ - public static FluentExp greatest (SQLExpression arg1, - SQLExpression arg2) + public static FluentExp greatest (SQLExpression arg1, + SQLExpression arg2) { return new Greatest(arg1, arg2); } @@ -136,7 +136,7 @@ public class Funcs /** * Creates an expression that evaluates to the largest of the given expressions. */ - public static FluentExp greatest (SQLExpression... args) + public static FluentExp greatest (SQLExpression... args) { return new Greatest(args); } @@ -144,8 +144,8 @@ public class Funcs /** * Creates an expression that evaluates to the smallest of the given expressions. */ - public static FluentExp least (SQLExpression arg1, - SQLExpression arg2) + public static FluentExp least (SQLExpression arg1, + SQLExpression arg2) { return new Least(arg1, arg2); } @@ -153,7 +153,7 @@ public class Funcs /** * Creates an expression that evaluates to the smallest of the given expressions. */ - public static FluentExp least (SQLExpression... args) + public static FluentExp least (SQLExpression... args) { return new Least(args); } diff --git a/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java b/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java index 580ff31..f88acc8 100644 --- a/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java +++ b/src/main/java/com/samskivert/depot/impl/expression/ConditionalFun.java @@ -41,7 +41,7 @@ public abstract class ConditionalFun } } - public static class Greatest extends ManyArgFun { + public static class Greatest extends ManyArgFun { public Greatest (SQLExpression... args) { super(args); } @@ -56,7 +56,7 @@ public abstract class ConditionalFun } } - public static class Least extends ManyArgFun { + public static class Least extends ManyArgFun { public Least (SQLExpression... args) { super(args); }