Author: ruschein
Date: 2010-06-25 15:20:36 -0700 (Fri, 25 Jun 2010)
New Revision: 20666
Modified:
corelibs/trunk/equations/src/org/cytoscape/equations/Equation.java
Log:
Added a getErrorEquation() factory method to the Equation class.
Modified: corelibs/trunk/equations/src/org/cytoscape/equations/Equation.java
===================================================================
--- corelibs/trunk/equations/src/org/cytoscape/equations/Equation.java
2010-06-25 21:43:40 UTC (rev 20665)
+++ corelibs/trunk/equations/src/org/cytoscape/equations/Equation.java
2010-06-25 22:20:36 UTC (rev 20666)
@@ -30,15 +30,17 @@
package org.cytoscape.equations;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
public class Equation {
- final String equation;
- final Set<String> attribReferences;
- final Object[] code;
- final int[] sourceLocations;
- final Class type;
+ private String equation;
+ private final Set<String> attribReferences;
+ private final Object[] code;
+ private final int[] sourceLocations;
+ private final Class type;
/**
* @param equation the string representing this equation
@@ -70,4 +72,22 @@
public Object[] getCode() { return code; }
public int[] getSourceLocations() { return sourceLocations; }
public Class getType() { return type; }
+
+ /**
+ * A factory method that returns an Equation that always fails at
runtime.
+ *
+ * @param equation an arbitrary string that is usually a
syntactically invalid equation
+ * @param errorMessage the runtime error message that the returned
equation will produce
+ */
+ public static Equation getErrorEquation(final String equation, final
String errorMessage) {
+ final EqnCompiler compiler = new EqnCompiler();
+ final Map<String, Class> attribNameToTypeMap = new
HashMap<String, Class>();
+ if (!compiler.compile("=ERROR(" + errorMessage + ")",
attribNameToTypeMap))
+ throw new IllegalStateException("internal error in
Equation.getErrorEquation(). This should *never* happen!");
+
+ final Equation retVal = compiler.getEquation();
+ retVal.equation = equation;
+
+ return retVal;
+ }
}
--
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.