Skip to content

Commit 9603129

Browse files
committed
Adding new function cljcol to convert cell list to clojure collection
1 parent 775ea0c commit 9603129

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

registry/data/org/openoffice/Office/CalcAddins.xcu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
</node>
3030
</node>
3131
</node>
32-
<node oor:name="clcol" oor:op="replace">
32+
<node oor:name="cljcol" oor:op="replace">
3333
<prop oor:name="DisplayName">
34-
<value xml:lang="en">clcol</value>
34+
<value xml:lang="en">cljcol</value>
3535
</prop>
3636
<prop oor:name="Description">
37-
Return a cell
37+
Convert cells into a Clojure collection
3838
<value/>
3939
</prop>
4040
<prop oor:name="Category">

src/com/github/beothorn/clojurecalc/ClojureCalcImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public String clj(String exp)
7979
return ClojureInterpreter.runClojure(exp);
8080
}
8181

82-
public String clcol(XCellRange cells){
83-
return "On compile XCellRange on idl gives some error, will investigate";
82+
public String cljcol(String[][] cells){
83+
return ClojureInterpreter.toClojureCollection(cells);
8484
}
8585
}

src/com/github/beothorn/clojurecalc/ClojureInterpreter.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66
import java.util.Iterator;
77

88
public class ClojureInterpreter {
9+
10+
public static String toClojureCollection(String[][] javaMatrix){
11+
12+
if(javaMatrix.length <= 1){
13+
return getLine(javaMatrix[0]);
14+
}else{
15+
String result = "[";
16+
for (int i = 0; i < javaMatrix.length; i++) {
17+
result += getLine(javaMatrix[i])+" ";
18+
}
19+
result = result.substring(0, result.length() - 1);
20+
result += "]";
21+
return result;
22+
}
23+
}
24+
25+
private static String getLine(final String[] line) {
26+
String result = "[";
27+
for (int i = 0; i < line.length; i++) {
28+
result += line[i]+" ";
29+
}
30+
result = result.substring(0, result.length() - 1);
31+
result += "]";
32+
return result;
33+
}
34+
935
public static String runClojure(String exp){
1036
if(exp.equals("")) return "";
1137
String result;

src/com/github/beothorn/clojurecalc/XClojureCalc.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module com { module github { module beothorn { module clojurecalc {
2222

2323
string clj([in] string exp);
2424

25-
//string clcol([in] com::sun::star::table::XCellRange cells);
25+
string cljcol([in] sequence< sequence< string > > cells);
2626
};
2727
}; }; }; };
2828

src/description.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--Created with Apache OpenOffice API plug-in for NetBeans Version 2.0.6.000205-->
33
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink">
4-
<version value="0.0.1"/>
4+
<version value="0.1.0"/>
55
<identifier value="com.github.beothorn.clojurecalc.ClojureCalc"/>
66
</description>

test/com/github/beothorn/clojurecalc/ClojureInterpreterTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.beothorn.clojurecalc;
22

33
import junit.framework.TestCase;
4+
import junit.framework.Assert;
45

56
public class ClojureInterpreterTests extends TestCase{
67
public void testExp(){
@@ -10,9 +11,16 @@ public void testExp(){
1011
runAndAssert("(map #(* % 2) [1 2 3])", "[2 4 6]");
1112
runAndAssert("[ [ 2 4 6 ] ]", "[[2 4 6]]");
1213
}
14+
15+
public void testCellsToMatrix(){
16+
final String clojureCollection = ClojureInterpreter.toClojureCollection(new String[][]{{"1", "2", "3"}});
17+
Assert.assertEquals("[1 2 3]", clojureCollection);
18+
final String clojureCollectionCollections = ClojureInterpreter.toClojureCollection(new String[][]{{"1", "2", "3"},{"4", "5", "6"}});
19+
Assert.assertEquals("[[1 2 3] [4 5 6]]", clojureCollectionCollections);
20+
}
1321

1422
private void runAndAssert(final String exp, final String expected) {
1523
final String result = ClojureInterpreter.runClojure(exp);
16-
junit.framework.Assert.assertEquals(expected, result);
24+
Assert.assertEquals(expected, result);
1725
}
1826
}

0 commit comments

Comments
 (0)