/*
 * This file is part of Relaxe.
 * Copyright (c) 2014 Topi Nieminen
 * Author: Topi Nieminen <topi.nieminen@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA, 02110-1301 USA.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License.
 */
package com.appspot.relaxe.expr.op;

import com.appspot.relaxe.expr.Predicate;
import com.appspot.relaxe.expr.RowValueConstructor;
import com.appspot.relaxe.expr.Symbol;
import com.appspot.relaxe.expr.ValueExpression;

public class Comparison
	extends BinaryOperator
	implements Predicate {
		
	/**
	 * 
	 */
	private static final long serialVersionUID = 6172456596029288843L;

	public enum Op {
		EQ(Symbol.EQUALS),
		LE(Symbol.LESS_OR_EQUAL),
		GE(Symbol.GREATER_OR_EQUAL),
		LT(Symbol.LESS_THAN),
		GT(Symbol.GREATER_THAN),
		;
				
		private Symbol symbol;
		
		private Op() {			
		}
		
		private Op(Symbol symbol) {
			this.symbol = symbol;			
		}
		
		public Comparison newComparison(ValueExpression a, ValueExpression b) {
			return new Comparison(this, a, b);
		}
		
		public Comparison newComparison(RowValueConstructor a, RowValueConstructor b) {
			return new Comparison(this, a, b);
		}
	}
	
	/**
	 * No-argument constructor for GWT Serialization
	 */
	protected Comparison() {
	}
	
	private Comparison(Op op, ValueExpression a, ValueExpression b) {
		super(op.symbol, a, b);	
	}
	
	private Comparison(Op op, RowValueConstructor a, RowValueConstructor b) {
		super(op.symbol, a, b);	
	}		
	
	public static Comparison eq(ValueExpression a, ValueExpression b) {
		return new Comparison(Op.EQ, a, b);
	}
	
	public static Comparison lt(ValueExpression a, ValueExpression b) {
		return new Comparison(Op.LT, a, b);
	}	
	
	public static Comparison gt(ValueExpression a, ValueExpression b) {
		return new Comparison(Op.GT, a, b);
	}
	
	public static Comparison eq(RowValueConstructor a, RowValueConstructor b) {
		return new Comparison(Op.EQ, a, b);
	}
}

@@ -1081,16 +1081,56 @@
 pr.op;%0A%0A
+import com.appspot.relaxe.expr.Keyword;%0A
 import c
@@ -1215,16 +1215,59 @@
 ructor;%0A
+import com.appspot.relaxe.expr.SQLKeyword;%0A
 import c
@@ -1297,16 +1297,54 @@
 Symbol;%0A
+import com.appspot.relaxe.expr.Token;%0A
 import c
@@ -1692,16 +1692,41 @@
 _THAN),%0A
+%09%09LIKE(SQLKeyword.LIKE),%0A
 %09%09;%0A%09%09%09%09
@@ -1736,22 +1736,21 @@
 private 
-Symbol
+Token
  symbol;
@@ -1837,32 +1837,100 @@
 mbol;%09%09%09%0A%09%09%7D%0A%09%09%0A
+%09%09private Op(Keyword keyword) %7B%0A%09%09%09this.symbol = keyword;%09%09%09%0A%09%09%7D%0A%09%09%0A
 %09%09public Compari
@@ -2786,32 +2786,147 @@
 Op.GT, a, b);%0A%09%7D
+%0A%0A%09public static Comparison like(ValueExpression a, ValueExpression b) %7B%0A%09%09return new Comparison(Op.LIKE, a, b);%0A%09%7D
 %0A%09%0A%09public stati
@@ -3030,10 +3030,13 @@
  b);%0A%09%7D%0A
+%09%09%0A
 %7D%0A

Add LIKE predicate