src/core/net/sf/basedb/util/export/spotdata/SimpleDynamicField.java

Code
Comments
Other
Rev Date Author Line
4925 08 May 09 nicklas 1 /**
4925 08 May 09 nicklas 2   $Id$
4925 08 May 09 nicklas 3
4925 08 May 09 nicklas 4   Copyright (C) 2009 Nicklas Nordborg
4925 08 May 09 nicklas 5
4925 08 May 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4925 08 May 09 nicklas 7   Available at http://base.thep.lu.se/
4925 08 May 09 nicklas 8
4925 08 May 09 nicklas 9   BASE is free software; you can redistribute it and/or
4925 08 May 09 nicklas 10   modify it under the terms of the GNU General Public License
4925 08 May 09 nicklas 11   as published by the Free Software Foundation; either version 3
4925 08 May 09 nicklas 12   of the License, or (at your option) any later version.
4925 08 May 09 nicklas 13
4925 08 May 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4925 08 May 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4925 08 May 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4925 08 May 09 nicklas 17   GNU General Public License for more details.
4925 08 May 09 nicklas 18
4925 08 May 09 nicklas 19   You should have received a copy of the GNU General Public License
4925 08 May 09 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4925 08 May 09 nicklas 21 */
4925 08 May 09 nicklas 22 package net.sf.basedb.util.export.spotdata;
4925 08 May 09 nicklas 23
4925 08 May 09 nicklas 24 import net.sf.basedb.core.BioAssaySet;
4925 08 May 09 nicklas 25 import net.sf.basedb.core.DbControl;
5319 20 Apr 10 nicklas 26 import net.sf.basedb.core.DynamicQuery;
4925 08 May 09 nicklas 27 import net.sf.basedb.core.Formula;
4925 08 May 09 nicklas 28 import net.sf.basedb.core.IntensityTransform;
5319 20 Apr 10 nicklas 29 import net.sf.basedb.core.Type;
4925 08 May 09 nicklas 30 import net.sf.basedb.core.query.Expression;
5319 20 Apr 10 nicklas 31 import net.sf.basedb.util.EqualsHelper;
4925 08 May 09 nicklas 32 import net.sf.basedb.util.formatter.Formatter;
4925 08 May 09 nicklas 33
4925 08 May 09 nicklas 34 /**
4925 08 May 09 nicklas 35   Represents an exported data field. The object consists
4925 08 May 09 nicklas 36   of a predefined query expression that can be used in the 
4925 08 May 09 nicklas 37   export query to select the data that is going to be exported, and
5319 20 Apr 10 nicklas 38   a title that is exported as part of the table header. One 
5319 20 Apr 10 nicklas 39   instance of this class is considered to be equal to another if 
5319 20 Apr 10 nicklas 40   they are configured with the same expression and title.
4925 08 May 09 nicklas 41
4925 08 May 09 nicklas 42   @author Nicklas
4925 08 May 09 nicklas 43   @version 2.12
4925 08 May 09 nicklas 44   @base.modified $Date$
4925 08 May 09 nicklas 45 */
4925 08 May 09 nicklas 46 public class SimpleDynamicField
4925 08 May 09 nicklas 47   implements DynamicField
4925 08 May 09 nicklas 48 {
4925 08 May 09 nicklas 49
4925 08 May 09 nicklas 50   private Expression expression;
4925 08 May 09 nicklas 51   private Formula.AverageMethod averageMethod;
4925 08 May 09 nicklas 52   private Formatter<?> formatter;
4925 08 May 09 nicklas 53   private String title;
5319 20 Apr 10 nicklas 54   private Type type;
4925 08 May 09 nicklas 55   
4925 08 May 09 nicklas 56   /**
4925 08 May 09 nicklas 57     Create a new object. Before it can be used it must be configured.
4925 08 May 09 nicklas 58   */
4925 08 May 09 nicklas 59   public SimpleDynamicField()
4925 08 May 09 nicklas 60   {}
4925 08 May 09 nicklas 61     
4925 08 May 09 nicklas 62   /*
4925 08 May 09 nicklas 63     From the DynamicField interface
4925 08 May 09 nicklas 64     -------------------------------
4925 08 May 09 nicklas 65   */
4925 08 May 09 nicklas 66   @Override
4925 08 May 09 nicklas 67   public String getTitle()
4925 08 May 09 nicklas 68   {
4925 08 May 09 nicklas 69     return title;
4925 08 May 09 nicklas 70   }
4925 08 May 09 nicklas 71   /**
4925 08 May 09 nicklas 72     Returns the configured expression. If 'forAverage' is TRUE the 
5385 13 Aug 10 nicklas 73     confgured {@link net.sf.basedb.core.Formula.AverageMethod} is allowed to transform
4925 08 May 09 nicklas 74     the expression. If no average method has been configured the 
4925 08 May 09 nicklas 75     average method specified by the {@link IntensityTransform} from
4925 08 May 09 nicklas 76     the 'source' bioassay set is used.
4925 08 May 09 nicklas 77   */
4925 08 May 09 nicklas 78   @Override
5319 20 Apr 10 nicklas 79   public Expression getExpression(DbControl dc, DynamicQuery query, BioAssaySet source, boolean forAverage)
4925 08 May 09 nicklas 80   {
4925 08 May 09 nicklas 81     Expression e = getExpression();
4925 08 May 09 nicklas 82     if (forAverage && e != null)
4925 08 May 09 nicklas 83     {
4925 08 May 09 nicklas 84       Formula.AverageMethod avg = averageMethod == null ?
4925 08 May 09 nicklas 85           source.getIntensityTransform().getAverageMethod() : averageMethod;
4925 08 May 09 nicklas 86       e = avg.getAverageExpression(e);
4925 08 May 09 nicklas 87     }
4925 08 May 09 nicklas 88     return e;
4925 08 May 09 nicklas 89   }
4925 08 May 09 nicklas 90   @Override
5319 20 Apr 10 nicklas 91   public Type getType()
5319 20 Apr 10 nicklas 92   {
5319 20 Apr 10 nicklas 93     return type;
5319 20 Apr 10 nicklas 94   }
5319 20 Apr 10 nicklas 95   @Override
4925 08 May 09 nicklas 96   public Formatter<?> getFormatter()
4925 08 May 09 nicklas 97   {
4925 08 May 09 nicklas 98     return formatter;
4925 08 May 09 nicklas 99   }
4925 08 May 09 nicklas 100   // --------------------------------------------
5319 20 Apr 10 nicklas 101
5319 20 Apr 10 nicklas 102   /**
5319 20 Apr 10 nicklas 103     A dynamic field is equal to another field if it uses the same
5319 20 Apr 10 nicklas 104     expression and has the same title. 
5319 20 Apr 10 nicklas 105     @since 2.15
5319 20 Apr 10 nicklas 106   */
5319 20 Apr 10 nicklas 107   @Override
5319 20 Apr 10 nicklas 108   public boolean equals(Object obj)
5319 20 Apr 10 nicklas 109   {
5319 20 Apr 10 nicklas 110     if (this == obj) return true;
5320 21 Apr 10 nicklas 111     if (!(obj instanceof SimpleDynamicField)) return false;
5319 20 Apr 10 nicklas 112     SimpleDynamicField other = (SimpleDynamicField)obj;
5320 21 Apr 10 nicklas 113     return EqualsHelper.equals(this.getExpression(), other.getExpression()) 
5319 20 Apr 10 nicklas 114       && EqualsHelper.equals(this.getTitle(), other.getTitle());
5319 20 Apr 10 nicklas 115   }
4925 08 May 09 nicklas 116   
4925 08 May 09 nicklas 117   /**
5319 20 Apr 10 nicklas 118     @since 2.15
5319 20 Apr 10 nicklas 119   */
5319 20 Apr 10 nicklas 120   @Override
5319 20 Apr 10 nicklas 121   public int hashCode()
5319 20 Apr 10 nicklas 122   {
5320 21 Apr 10 nicklas 123     return 13 * EqualsHelper.hashCode(getExpression()) + EqualsHelper.hashCode(getTitle());
5319 20 Apr 10 nicklas 124   }
5319 20 Apr 10 nicklas 125   /**
5319 20 Apr 10 nicklas 126      @since 2.15
5319 20 Apr 10 nicklas 127   */
5319 20 Apr 10 nicklas 128   @Override
5319 20 Apr 10 nicklas 129   public String toString()
5319 20 Apr 10 nicklas 130   {
5319 20 Apr 10 nicklas 131     return "SimpleDynamicField(title=" + getTitle() + "; expression=" + getExpression() + ")";
5319 20 Apr 10 nicklas 132   }
5319 20 Apr 10 nicklas 133
5319 20 Apr 10 nicklas 134   /**
4925 08 May 09 nicklas 135      Get the configured express.
4925 08 May 09 nicklas 136   */
4925 08 May 09 nicklas 137   public Expression getExpression()
4925 08 May 09 nicklas 138   {
4925 08 May 09 nicklas 139     return expression;
4925 08 May 09 nicklas 140   }
4925 08 May 09 nicklas 141   
4925 08 May 09 nicklas 142   /**
4925 08 May 09 nicklas 143     Set the expression used to select data in the query.
4925 08 May 09 nicklas 144   */
4925 08 May 09 nicklas 145   public void setExpression(Expression expression)
4925 08 May 09 nicklas 146   {
4925 08 May 09 nicklas 147     this.expression = expression;
4925 08 May 09 nicklas 148   }
4925 08 May 09 nicklas 149
4925 08 May 09 nicklas 150   /**
4925 08 May 09 nicklas 151     Set the column header title.
4925 08 May 09 nicklas 152   */
4925 08 May 09 nicklas 153   public void setTitle(String title)
4925 08 May 09 nicklas 154   {
4925 08 May 09 nicklas 155     this.title = title;
4925 08 May 09 nicklas 156   }
4925 08 May 09 nicklas 157   
4925 08 May 09 nicklas 158   /**
5319 20 Apr 10 nicklas 159     Set the data type of the exported field.
5319 20 Apr 10 nicklas 160     @since 2.15
5319 20 Apr 10 nicklas 161   */
5319 20 Apr 10 nicklas 162   public void setType(Type type)
5319 20 Apr 10 nicklas 163   {
5319 20 Apr 10 nicklas 164     this.type = type;
5319 20 Apr 10 nicklas 165   }
5319 20 Apr 10 nicklas 166   
5319 20 Apr 10 nicklas 167   /**
4925 08 May 09 nicklas 168     Get the average method to use if the exporter is exporting
4925 08 May 09 nicklas 169     averaged data. If no average method has been configured, the
4925 08 May 09 nicklas 170     everage method specified by the {@link IntensityTransform}
4925 08 May 09 nicklas 171     of the source bioassay set is used.
4925 08 May 09 nicklas 172   */
4925 08 May 09 nicklas 173   public Formula.AverageMethod getAverageMethod()
4925 08 May 09 nicklas 174   {
4925 08 May 09 nicklas 175     return averageMethod;
4925 08 May 09 nicklas 176   }
4925 08 May 09 nicklas 177   
4925 08 May 09 nicklas 178   /**
4925 08 May 09 nicklas 179     Set the average method to use when exporting averaged data.
4925 08 May 09 nicklas 180   */
4925 08 May 09 nicklas 181   public void setAverageMethod(Formula.AverageMethod averageMethod)
4925 08 May 09 nicklas 182   {
4925 08 May 09 nicklas 183     this.averageMethod = averageMethod;
4925 08 May 09 nicklas 184   }
4925 08 May 09 nicklas 185
4925 08 May 09 nicklas 186   /**
4925 08 May 09 nicklas 187     Set a formatter to use for formatting the exported values.
4925 08 May 09 nicklas 188   */
4925 08 May 09 nicklas 189   public void setFormatter(Formatter<?> formatter)
4925 08 May 09 nicklas 190   {
4925 08 May 09 nicklas 191     this.formatter = formatter;
4925 08 May 09 nicklas 192   }
4925 08 May 09 nicklas 193   
4925 08 May 09 nicklas 194 }