Author: ruschein
Date: 2010-09-03 12:48:21 -0700 (Fri, 03 Sep 2010)
New Revision: 21688
Added:
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/builtins/Concatenate.java
corelibs/trunk/equations/src/test/java/org/cytoscape/equations/builtins/ConcatenateTest.java
Modified:
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/Parser.java
Log:
Added new CONCATENATE() built-in function.
Modified:
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/Parser.java
===================================================================
--- corelibs/trunk/equations/src/main/java/org/cytoscape/equations/Parser.java
2010-09-03 18:22:26 UTC (rev 21687)
+++ corelibs/trunk/equations/src/main/java/org/cytoscape/equations/Parser.java
2010-09-03 19:48:21 UTC (rev 21688)
@@ -51,6 +51,7 @@
eqnParser.registerFunction(new Average());
eqnParser.registerFunction(new BList());
eqnParser.registerFunction(new Combin());
+ eqnParser.registerFunction(new Concatenate());
eqnParser.registerFunction(new Cos());
eqnParser.registerFunction(new Cosh());
eqnParser.registerFunction(new Count());
Copied:
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/builtins/Concatenate.java
(from rev 21668,
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/builtins/SList.java)
===================================================================
---
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/builtins/Concatenate.java
(rev 0)
+++
corelibs/trunk/equations/src/main/java/org/cytoscape/equations/builtins/Concatenate.java
2010-09-03 19:48:21 UTC (rev 21688)
@@ -0,0 +1,80 @@
+/*
+ File: Concatenate.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 org.cytoscape.equations.AbstractFunction;
+import org.cytoscape.equations.ArgDescriptor;
+import org.cytoscape.equations.ArgType;
+import org.cytoscape.equations.FunctionUtil;
+import org.cytoscape.equations.StringList;
+
+
+public class Concatenate extends AbstractFunction {
+ public Concatenate() {
+ super(new ArgDescriptor[] {
+ new ArgDescriptor(ArgType.OPT_STRINGS,
"strings", "Zero or more numbers, strings or booleans or lists thereof."),
+ });
+ }
+
+ /**
+ * 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 "CONCATENATE"; }
+
+ /**
+ * Used to provide help for users.
+ * @return a description of what this function does
+ */
+ public String getFunctionSummary() { return "Returns a string (a.k.a.
text object)."; }
+
+ public Class getReturnType() { return String.class; }
+
+ /**
+ * @param args the function arguments which must be either one or two
objects of type Double
+ * @return the result of the function evaluation which is the maximum
of the elements in the single list argument or the maximum of the one or more
double arguments
+ * @throws ArithmeticException
+ * @throws IllegalArgumentException thrown if any of the arguments is
not of type Double
+ */
+ public Object evaluateFunction(final Object[] args) throws
IllegalArgumentException, ArithmeticException {
+ final String[] strings = FunctionUtil.getStrings(args);
+
+ int totalLength = 0;
+ for (final String s : strings)
+ totalLength += s.length();
+
+ final StringBuilder builder = new StringBuilder(totalLength);
+ for (final String s : strings)
+ builder.append(s);
+
+ return builder.toString();
+ }
+}
Copied:
corelibs/trunk/equations/src/test/java/org/cytoscape/equations/builtins/ConcatenateTest.java
(from rev 21668,
corelibs/trunk/equations/src/test/java/org/cytoscape/equations/builtins/SListTest.java)
===================================================================
---
corelibs/trunk/equations/src/test/java/org/cytoscape/equations/builtins/ConcatenateTest.java
(rev 0)
+++
corelibs/trunk/equations/src/test/java/org/cytoscape/equations/builtins/ConcatenateTest.java
2010-09-03 19:48:21 UTC (rev 21688)
@@ -0,0 +1,54 @@
+/*
+ File: ConcatenateTest.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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.*;
+
+
+public class ConcatenateTest extends TestCase {
+ public void testAll() throws Exception {
+ final List<Object> numbers = new ArrayList<Object>();
+ numbers.add(Double.valueOf(1.0));
+ numbers.add(Integer.valueOf(2));
+ numbers.add(Double.valueOf(3.0));
+ numbers.add("4.01");
+ numbers.add(Double.valueOf(5.0));
+ final Map<String, Object> variablesAndValues = new
HashMap<String, Object>();
+ variablesAndValues.put("numbers", numbers);
+ assertTrue(Framework.executeTest("=Concatenate($numbers,
\"ab\", \"\")", variablesAndValues, "1234.015ab"));
+ assertTrue(Framework.executeTest("=CONCATENATE()", ""));
+ }
+}
--
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.