/* 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; import java.util.logging.Logger; /** * Holds the name of a single field attribute for inclusion in a query. * Implements hashCode() and equals() for simple retrieval from Collections. * * @author <a href="mailto:craig@ebi.ac.uk">Craig Melsopp</a> * @author <a href="maito:dlondon@ebi.ac.uk">Darin London</a> */ public class FieldAttribute implements Attribute { private final static Logger logger = Logger.getLogger(FieldAttribute.class.getName()); /** * constructs a FieldAttribute with the given field name * * @param field - String name of attribute to retrieve (roughly * corresponds to a field of a table in the mart database). */ public FieldAttribute(String field) { this(field, null, null); } /** * constructs a FieldAttribute with the given field name * * @param field - String name of attribute to retrieve (roughly * corresponds to a field of a table in the mart database). */ public FieldAttribute(String field, String tableConstraint,String key) { this.field = field; this.tableConstraint = tableConstraint; this.key = key; hashcode = 17; hashcode = 37*hashcode + ((field == null) ? 0 : field.hashCode()); hashcode = 37*hashcode + ((tableConstraint == null) ? 0 : tableConstraint.hashCode()); hashcode = 37*hashcode + ((key == null) ? 0 : key.hashCode()); } /** * returns the field name * * @return String field */ public String getField(){ return field; } /** * Returns the table constraint * @return String tableConstraint */ public String getTableConstraint() { return tableConstraint; } public String getKey() { return key; } public int hashCode() { return hashcode; } /** * Allows Equality Comparisons manipulation of FieldAttribute objects */ public boolean equals(Object o) { return o instanceof FieldAttribute && hashCode() == ((FieldAttribute) o).hashCode(); } /** * returns a description of the attribute, for use by logging systems * * @return String attribute description (field=field) */ 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(" ]"); return buf.toString(); } private final String tableConstraint; private final String key; private final String field; private int hashcode = 0; /** * @see org.ensembl.mart.lib.Attribute#sameFieldTableConstraint(org.ensembl.mart.lib.Attribute) */ public boolean sameFieldTableConstraint(Attribute attribute) { String f = getField(); String f2 = attribute.getField(); String tc = getTableConstraint(); String tc2 = attribute.getTableConstraint(); if ( f==null ) {//some atts don't have a field in new XML - turn off warning //logger.warning("Datasetconfig bug, field missing in FieldAttribute :" + this); return false; } return f.equals(attribute.getField()) && ((tc == tc2) || (tc != null && tc.equals(tc2))); } }