src/core/net/sf/basedb/util/jep/JepExpressionFunction.java

Code
Comments
Other
Rev Date Author Line
2086 17 Mar 06 nicklas 1 /*
2086 17 Mar 06 nicklas 2   $Id$
2086 17 Mar 06 nicklas 3
4889 06 Apr 09 nicklas 4   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
2086 17 Mar 06 nicklas 5
2304 22 May 06 jari 6   This file is part of BASE - BioArray Software Environment.
2304 22 May 06 jari 7   Available at http://base.thep.lu.se/
2086 17 Mar 06 nicklas 8
2086 17 Mar 06 nicklas 9   BASE is free software; you can redistribute it and/or
2086 17 Mar 06 nicklas 10   modify it under the terms of the GNU General Public License
4479 05 Sep 08 jari 11   as published by the Free Software Foundation; either version 3
2086 17 Mar 06 nicklas 12   of the License, or (at your option) any later version.
2086 17 Mar 06 nicklas 13
2086 17 Mar 06 nicklas 14   BASE is distributed in the hope that it will be useful,
2086 17 Mar 06 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
2086 17 Mar 06 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2086 17 Mar 06 nicklas 17   GNU General Public License for more details.
2086 17 Mar 06 nicklas 18
2086 17 Mar 06 nicklas 19   You should have received a copy of the GNU General Public License
4515 11 Sep 08 jari 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
2086 17 Mar 06 nicklas 21 */
2086 17 Mar 06 nicklas 22 package net.sf.basedb.util.jep;
2086 17 Mar 06 nicklas 23
2086 17 Mar 06 nicklas 24 import net.sf.basedb.core.query.Expression;
2086 17 Mar 06 nicklas 25
2086 17 Mar 06 nicklas 26 import org.nfunk.jep.Node;
2086 17 Mar 06 nicklas 27
2086 17 Mar 06 nicklas 28 /**
2086 17 Mar 06 nicklas 29   This interface should be implemented by JEP functions
2086 17 Mar 06 nicklas 30   that can also be converted into an {@link Expression} that
2086 17 Mar 06 nicklas 31   can be used in queries.
2086 17 Mar 06 nicklas 32
2086 17 Mar 06 nicklas 33   @author Nicklas
2086 17 Mar 06 nicklas 34   @version 2.0
2086 17 Mar 06 nicklas 35   @base.modified $Date$
2086 17 Mar 06 nicklas 36   @see Jep#formulaToExpression(String, JepFunction[])
2086 17 Mar 06 nicklas 37 */
2086 17 Mar 06 nicklas 38 public interface JepExpressionFunction
2086 17 Mar 06 nicklas 39   extends JepFunction
2086 17 Mar 06 nicklas 40 {
2086 17 Mar 06 nicklas 41
2086 17 Mar 06 nicklas 42   /**
2086 17 Mar 06 nicklas 43     Convert this function to an {@link Expression} that can be used
2086 17 Mar 06 nicklas 44     in a query. The implementation must check that the node contains
2086 17 Mar 06 nicklas 45     the correct number of children (ie. arguments to the function)
2086 17 Mar 06 nicklas 46     and convert the arguments to whatever is suitable for the expression.
2086 17 Mar 06 nicklas 47     Example from the {@link Log2Function}
2086 17 Mar 06 nicklas 48     <pre class="code">
2086 17 Mar 06 nicklas 49 int numChildren = node.jjtGetNumChildren();
2086 17 Mar 06 nicklas 50 if (numChildren != 1)
2086 17 Mar 06 nicklas 51 {
2086 17 Mar 06 nicklas 52    throw new BaseException("Invalid number of arguments for 'log2' function: " + numChildren);
2086 17 Mar 06 nicklas 53 }
2086 17 Mar 06 nicklas 54 return Expressions.log2(Jep.nodeToExpression(node.jjtGetChild(0)));
2086 17 Mar 06 nicklas 55 </pre>
2086 17 Mar 06 nicklas 56
2086 17 Mar 06 nicklas 57     @param node The node representing this function
2086 17 Mar 06 nicklas 58     @return An <code>Expression</code> object
2086 17 Mar 06 nicklas 59   */
2086 17 Mar 06 nicklas 60   public Expression toExpression(Node node);
2086 17 Mar 06 nicklas 61 }