2086 |
17 Mar 06 |
nicklas |
1 |
/* |
2086 |
17 Mar 06 |
nicklas |
$Id$ |
2086 |
17 Mar 06 |
nicklas |
3 |
|
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
2086 |
17 Mar 06 |
nicklas |
5 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
2086 |
17 Mar 06 |
nicklas |
8 |
|
2086 |
17 Mar 06 |
nicklas |
BASE is free software; you can redistribute it and/or |
2086 |
17 Mar 06 |
nicklas |
modify it under the terms of the GNU General Public License |
4479 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
2086 |
17 Mar 06 |
nicklas |
of the License, or (at your option) any later version. |
2086 |
17 Mar 06 |
nicklas |
13 |
|
2086 |
17 Mar 06 |
nicklas |
BASE is distributed in the hope that it will be useful, |
2086 |
17 Mar 06 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2086 |
17 Mar 06 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2086 |
17 Mar 06 |
nicklas |
GNU General Public License for more details. |
2086 |
17 Mar 06 |
nicklas |
18 |
|
2086 |
17 Mar 06 |
nicklas |
You should have received a copy of the GNU General Public License |
4515 |
11 Sep 08 |
jari |
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 |
This interface should be implemented by JEP functions |
2086 |
17 Mar 06 |
nicklas |
that can also be converted into an {@link Expression} that |
2086 |
17 Mar 06 |
nicklas |
can be used in queries. |
2086 |
17 Mar 06 |
nicklas |
32 |
|
2086 |
17 Mar 06 |
nicklas |
@author Nicklas |
2086 |
17 Mar 06 |
nicklas |
@version 2.0 |
2086 |
17 Mar 06 |
nicklas |
@base.modified $Date$ |
2086 |
17 Mar 06 |
nicklas |
@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 |
Convert this function to an {@link Expression} that can be used |
2086 |
17 Mar 06 |
nicklas |
in a query. The implementation must check that the node contains |
2086 |
17 Mar 06 |
nicklas |
the correct number of children (ie. arguments to the function) |
2086 |
17 Mar 06 |
nicklas |
and convert the arguments to whatever is suitable for the expression. |
2086 |
17 Mar 06 |
nicklas |
Example from the {@link Log2Function} |
2086 |
17 Mar 06 |
nicklas |
<pre class="code"> |
2086 |
17 Mar 06 |
nicklas |
int numChildren = node.jjtGetNumChildren(); |
2086 |
17 Mar 06 |
nicklas |
if (numChildren != 1) |
2086 |
17 Mar 06 |
nicklas |
51 |
{ |
2086 |
17 Mar 06 |
nicklas |
throw new BaseException("Invalid number of arguments for 'log2' function: " + numChildren); |
2086 |
17 Mar 06 |
nicklas |
53 |
} |
2086 |
17 Mar 06 |
nicklas |
return Expressions.log2(Jep.nodeToExpression(node.jjtGetChild(0))); |
2086 |
17 Mar 06 |
nicklas |
</pre> |
2086 |
17 Mar 06 |
nicklas |
56 |
|
2086 |
17 Mar 06 |
nicklas |
@param node The node representing this function |
2086 |
17 Mar 06 |
nicklas |
@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 |
} |