diff --git a/src/main/java/com/samskivert/depot/impl/BuildVisitor.java b/src/main/java/com/samskivert/depot/impl/BuildVisitor.java index 2684e4e..2841c8b 100644 --- a/src/main/java/com/samskivert/depot/impl/BuildVisitor.java +++ b/src/main/java/com/samskivert/depot/impl/BuildVisitor.java @@ -38,7 +38,6 @@ import com.samskivert.depot.expression.*; import com.samskivert.depot.operator.Case; import com.samskivert.depot.operator.FullText; import com.samskivert.depot.util.ByteEnum; -import com.samskivert.depot.util.Tuple2; import static com.samskivert.depot.Log.log; import com.samskivert.depot.impl.clause.*; @@ -176,11 +175,11 @@ public abstract class BuildVisitor implements FragmentVisitor public Void visit (Case caseExp) { _builder.append("(case "); - for (Tuple2, SQLExpression> tuple : caseExp.getWhenExps()) { + for (Case.Exp exp : caseExp.getWhenExps()) { _builder.append(" when "); - tuple.a.accept(this); + exp.when.accept(this); _builder.append(" then "); - tuple.b.accept(this); + exp.then.accept(this); } SQLExpression elseExp = caseExp.getElseExp(); if (elseExp != null) { diff --git a/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java b/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java index 5395ee7..5ccc0c8 100644 --- a/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java +++ b/src/main/java/com/samskivert/depot/impl/ExpressionEvaluator.java @@ -9,7 +9,6 @@ import java.util.Arrays; import com.samskivert.depot.Key; import com.samskivert.depot.PersistentRecord; -import com.samskivert.depot.util.Tuple2; import com.samskivert.depot.clause.Distinct; import com.samskivert.depot.clause.FieldDefinition; @@ -145,13 +144,13 @@ public class ExpressionEvaluator public Object visit (Case caseExp) { - for (Tuple2, SQLExpression> exp : caseExp.getWhenExps()) { - Object result = exp.a.accept(this); + for (Case.Exp exp : caseExp.getWhenExps()) { + Object result = exp.when.accept(this); if (result instanceof NoValue || !(result instanceof Boolean)) { - return new NoValue("Failed to evaluate case: " + exp.a + " -> " + result); + return new NoValue("Failed to evaluate case: " + exp.when + " -> " + result); } if (((Boolean) result).booleanValue()) { - return exp.b.accept(this); + return exp.then.accept(this); } } SQLExpression elseExp = caseExp.getElseExp(); diff --git a/src/main/java/com/samskivert/depot/operator/Case.java b/src/main/java/com/samskivert/depot/operator/Case.java index 27ad26e..8f07e14 100644 --- a/src/main/java/com/samskivert/depot/operator/Case.java +++ b/src/main/java/com/samskivert/depot/operator/Case.java @@ -12,24 +12,31 @@ import com.google.common.collect.Lists; import com.samskivert.depot.PersistentRecord; import com.samskivert.depot.expression.SQLExpression; import com.samskivert.depot.impl.FragmentVisitor; -import com.samskivert.depot.util.Tuple2; /** * The SQL 'case' operator. */ -public class Case - implements SQLExpression +public class Case implements SQLExpression { + public static class Exp { + public SQLExpression when; + public SQLExpression then; + public Exp (SQLExpression when, SQLExpression then) { + this.when = when; + this.then = then; + } + } + public Case (SQLExpression... exps) { int i = 0; for (; i + 1 < exps.length; i += 2) { - _whenExps.add(Tuple2., SQLExpression>create(exps[i], exps[i + 1])); + _whenExps.add(new Exp(exps[i], exps[i + 1])); } _elseExp = (i < exps.length) ? exps[i] : null; } - public List, SQLExpression>> getWhenExps () + public List getWhenExps () { return _whenExps; } @@ -48,9 +55,9 @@ public class Case // from SQLExpression public void addClasses (Collection> classSet) { - for (Tuple2, SQLExpression> tuple : _whenExps) { - tuple.a.addClasses(classSet); - tuple.b.addClasses(classSet); + for (Exp exp : _whenExps) { + exp.when.addClasses(classSet); + exp.then.addClasses(classSet); } if (_elseExp != null) { _elseExp.addClasses(classSet); @@ -62,9 +69,9 @@ public class Case { StringBuilder builder = new StringBuilder(); builder.append("Case("); - for (Tuple2, SQLExpression> tuple : _whenExps) { - builder.append(tuple.a.toString()).append("->"); - builder.append(tuple.b.toString()).append(","); + for (Exp exp : _whenExps) { + builder.append(exp.when.toString()).append("->"); + builder.append(exp.then.toString()).append(","); } if (_elseExp != null) { builder.append(_elseExp.toString()).append(")"); @@ -72,6 +79,6 @@ public class Case return builder.toString(); } - protected List, SQLExpression>> _whenExps = Lists.newArrayList(); + protected List _whenExps = Lists.newArrayList(); protected SQLExpression _elseExp; }