/*
 * Copyright (C) 2004-2005  exedio GmbH (www.exedio.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.exedio.cope;


public abstract class LiteralCondition extends Condition
{
	private final String operator; 
	public final Function attribute; // TODO rename to function
	public final Object value;

	protected LiteralCondition(final String operator, final Function attribute, final Object value)
	{
		this.operator = operator;
		this.attribute = attribute;
		this.value = value;

		if(operator==null)
			throw new NullPointerException();
		if(attribute==null)
			throw new NullPointerException();
		if(value==null)
			throw new NullPointerException();
	}
	
	final void append(final Statement bf)
	{
		bf.append(attribute, (Join)null);
		if(value!=null)
			bf.append(operator).
				appendParameter(attribute, value);
		else
			bf.append(" is null");
	}

	final void check(final Query query)
	{
		check(attribute, query);
	}

	public boolean equals(final Object other)
	{
		if(!(other instanceof LiteralCondition))
			return false;
		
		final LiteralCondition o = (LiteralCondition)other;
		
		return operator.equals(o.operator) && attribute.equals(o.attribute) && value.equals(o.value);
	}
	
	public int hashCode()
	{
		return operator.hashCode() ^ attribute.hashCode() ^ value.hashCode() ^ 918276;
	}

	public final String toString()
	{
		return attribute.toString() + operator + '\'' + value + '\'';
	}

}

@@ -943,45 +943,16 @@
 ion 
-attribute; // TODO rename to 
 function
 %0A%09pu
@@ -947,16 +947,17 @@
 function
+;
 %0A%09public
@@ -1044,25 +1044,24 @@
 unction 
-attribute
+function
 , final 
@@ -1116,29 +1116,27 @@
 his.
-attribute = attribute
+function = function
 ;%0A%09%09
@@ -1219,25 +1219,24 @@
 );%0A%09%09if(
-attribute
+function
 ==null)%0A
@@ -1386,25 +1386,24 @@
 .append(
-attribute
+function
 , (Join)
@@ -1471,25 +1471,24 @@
 rameter(
-attribute
+function
 , value)
@@ -1574,25 +1574,24 @@
 %09%09check(
-attribute
+function
 , query)
@@ -1802,25 +1802,24 @@
 tor) && 
-attribute
+function
 .equals(
@@ -1820,25 +1820,24 @@
 quals(o.
-attribute
+function
 ) && val
@@ -1918,25 +1918,24 @@
 ode() %5E 
-attribute
+function
 .hashCod
@@ -2019,17 +2019,16 @@
 urn 
-attribute
+function
 .toS

rename attribute to function