Author: ruschein
Date: 2010-06-25 14:43:40 -0700 (Fri, 25 Jun 2010)
New Revision: 20665
Added:
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Error.java
corelibs/trunk/equations/tests/org/cytoscape/equations/builtins/ErrorTest.java
Modified:
corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java
Log:
Added new ERROR() built-in function.
Modified: corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java
2010-06-25 21:29:09 UTC (rev 20664)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/Parser.java
2010-06-25 21:43:40 UTC (rev 20665)
@@ -55,6 +55,7 @@
eqnParser.registerFunction(new Cosh());
eqnParser.registerFunction(new Count());
eqnParser.registerFunction(new Degrees());
+ eqnParser.registerFunction(new
org.cytoscape.equations.builtins.Error());
eqnParser.registerFunction(new Exp());
eqnParser.registerFunction(new First());
eqnParser.registerFunction(new FList());
Copied:
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Error.java (from
rev 20662,
corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Abs.java)
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Error.java
(rev 0)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/builtins/Error.java
2010-06-25 21:43:40 UTC (rev 20665)
@@ -0,0 +1,94 @@
+/*
+ File: Error.java
+
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ 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
+ 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. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. 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.cytoscape.equations.builtins;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import org.cytoscape.equations.Function;
+
+
+public class Error implements Function {
+ /**
+ * Used to parse the function string. This name is treated in a
case-insensitive manner!
+ * @return the name by which you must call the function when used in
an attribute equation.
+ */
+ public String getName() { return "ERROR"; }
+
+ /**
+ * Used to provide help for users.
+ * @return a description of what this function does
+ */
+ public String getFunctionSummary() { return "Throws an exception at
runtime."; }
+
+ /**
+ * Used to provide help for users.
+ * @return a description of how to use this function
+ */
+ public String getUsageDescription() { return "Call this with
\"ERROR(message)\""; }
+
+ public Class getReturnType() { return String.class; }
+
+ /**
+ * @return Double.class or null if there is not exactly 1 arg or the
arg is not of type Double or Long
+ */
+ public Class validateArgTypes(final Class[] argTypes) {
+ if (argTypes.length != 1 || argTypes[0] != String.class)
+ return null;
+
+ return String.class;
+ }
+
+ /**
+ * @param args the function arguments which must be either one object
of type Double or Long
+ * @return the result of the function evaluation which is the natural
logarithm of the first argument
+ */
+ public Object evaluateFunction(final Object[] args) {
+ throw new IllegalStateException((String)args[0]);
+ }
+
+ /**
+ * Used with the equation builder.
+ *
+ * @param leadingArgs the types of the arguments that have already
been selected by the user.
+ * @return the set of arguments (must be a collection of String.class,
Long.class, Double.class,
+ * Boolean.class and List.class) that are candidates for the
next argument. An empty
+ * set indicates that no further arguments are valid.
+ */
+ public List<Class> getPossibleArgTypes(final Class[] leadingArgs) {
+ if (leadingArgs.length == 0) {
+ final List<Class> possibleNextArgs = new
ArrayList<Class>();
+ possibleNextArgs.add(String.class);
+ return possibleNextArgs;
+ }
+
+ return null;
+ }
+}
Copied:
corelibs/trunk/equations/tests/org/cytoscape/equations/builtins/ErrorTest.java
(from rev 20662,
corelibs/trunk/equations/tests/org/cytoscape/equations/builtins/AbsTest.java)
===================================================================
---
corelibs/trunk/equations/tests/org/cytoscape/equations/builtins/ErrorTest.java
(rev 0)
+++
corelibs/trunk/equations/tests/org/cytoscape/equations/builtins/ErrorTest.java
2010-06-25 21:43:40 UTC (rev 20665)
@@ -0,0 +1,40 @@
+/*
+ File: ErrorTest.java
+
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ 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
+ 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. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. 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.cytoscape.equations.builtins;
+
+
+import junit.framework.*;
+
+
+public class ErrorTest extends TestCase {
+ public void testAll() throws Exception {
+ assertTrue(Framework.executeTestExpectFailure("some message"));
+ }
+}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.