/* Generated by Together */ /* Copyright (C) 2003 EBI, GRL 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 org.ensembl.mart.lib; /** * Implimentation of a Filter object for null and not null filters, * eg, 'where x is null' or 'where x is not null' * * @author <a href="mailto:craig@ebi.ac.uk">Craig Melsopp</a> * @author <a href="mailto:dlondon@ebi.ac.uk">Darin London</a> */ public class BooleanFilter implements Filter { public static final String isNULL = " is null"; public static final String isNotNULL = " is not null"; public static final String isNULL_NUM = " != 1"; public static final String isNotNULL_NUM = " = 1"; /** * Constructor for a basic BooleanFilter, with field and qualifier set. * * @param field - String, field of filter * @param qualifier - String, one of isNULL or isNotNull */ public BooleanFilter(String field, String qualifier) { this(field, null, null,qualifier); } public BooleanFilter(String field, String tableConstraint, String key, String qualifier) { this.field = field; this.tableConstraint = tableConstraint; this.key = key; this.qualifier = qualifier; //this.handler = handler; hashcode = (this.field == null) ? 0 : this.field.hashCode(); hashcode = (this.tableConstraint != null) ? (31 * hashcode) + this.tableConstraint.hashCode() : hashcode; hashcode = (this.key != null) ? (31 * hashcode) + this.key.hashCode() : hashcode; hashcode = (this.qualifier != null) ? (31 * hashcode) + this.qualifier.hashCode() : hashcode; //hashcode = (this.handler != null) ? ( 31 * hashcode) + handler.hashCode() : hashcode; } /** * returns the field specified * * @return String field */ public String getField() { return field; } /** * returns the where clause for the SQL as field is null */ public String getWhereClause() { return field + qualifier; } /** * returns the right side of an SQL where clause */ public String getRightHandClause() { return qualifier; } /* * @see org.ensembl.mart.explorer.Filter#getValue() */ public String getValue() { return null; } public String getTableConstraint() { return tableConstraint; } public String getKey() { return key; } /* (non-Javadoc) * @see org.ensembl.mart.lib.Filter#getQualifier() */ public String getQualifier() { return qualifier; } public String toString() { StringBuffer buf = new StringBuffer(); buf.append("["); buf.append("field=").append(field); buf.append(", tableConstraint=").append(tableConstraint); buf.append(", key=").append(key); buf.append(", qualifier=").append(qualifier); buf.append(" ,value=").append(getValue()); //buf.append(", handler=").append(handler); buf.append("]"); return buf.toString(); } /** * Allows Equality Comparisons manipulation of BooleanFilter objects */ public boolean equals(Object o) { return o instanceof BooleanFilter && hashCode() == o.hashCode(); } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ public int hashCode() { return hashcode; } private final String field; private final String tableConstraint; private final String key; private final String qualifier; //private final String handler; private int hashcode = 0; //hashcode for immutable object }