r194 - in trunk/src: main/java/org/nuiton/j2r main/java/org/nuiton/j2r/types test/java/org/nuiton/j2r
Author: jcouteau Date: 2010-04-14 11:51:16 +0200 (Wed, 14 Apr 2010) New Revision: 194 Log: Clean code Modified: trunk/src/main/java/org/nuiton/j2r/RProxy.java trunk/src/main/java/org/nuiton/j2r/types/RDataFrame.java trunk/src/main/java/org/nuiton/j2r/types/REXPAbstract.java trunk/src/test/java/org/nuiton/j2r/DataframeTest.java trunk/src/test/java/org/nuiton/j2r/ListTest.java trunk/src/test/java/org/nuiton/j2r/NetTest.java Modified: trunk/src/main/java/org/nuiton/j2r/RProxy.java =================================================================== --- trunk/src/main/java/org/nuiton/j2r/RProxy.java 2010-04-12 12:15:23 UTC (rev 193) +++ trunk/src/main/java/org/nuiton/j2r/RProxy.java 2010-04-14 09:51:16 UTC (rev 194) @@ -55,7 +55,7 @@ */ public RProxy() throws RException { Boolean init = init(); - if (init == false) { + if (!init) { throw new RException( "R initialisation failed, please check your installation"); } Modified: trunk/src/main/java/org/nuiton/j2r/types/RDataFrame.java =================================================================== --- trunk/src/main/java/org/nuiton/j2r/types/RDataFrame.java 2010-04-12 12:15:23 UTC (rev 193) +++ trunk/src/main/java/org/nuiton/j2r/types/RDataFrame.java 2010-04-14 09:51:16 UTC (rev 194) @@ -19,12 +19,12 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -70,28 +70,30 @@ * @param datatypes a table object determining the type of each column of * the data.frame. * @param y the length of each vector that compound the data.frame. + * + * @throws RException if a datatype is not supported */ public RDataFrame(REngine engine, Object[] datatypes, int y) throws RException { super(); this.names = new ArrayList<String>(); this.rowNames = new ArrayList<String>(); - this.data = new ArrayList<List<? extends Object>>(); - for (int i = 0; i < datatypes.length; i++) { + this.data = new ArrayList<List<?>>(); + for (Object datatype : datatypes) { //create one column for each datatype element //check if type is supported - checkType(datatypes[i]); + checkType(datatype); //create the list of objects List<Object> column = new ArrayList<Object>(); //Fill it with instances of the datatype for (int j = 0; j < y; j++) { - if (datatypes[i] instanceof Double) { + if (datatype instanceof Double) { column.add(0.0); - } else if (datatypes[i] instanceof Integer) { + } else if (datatype instanceof Integer) { column.add(0); - } else if (datatypes[i] instanceof Boolean) { + } else if (datatype instanceof Boolean) { column.add(true); - } else if (datatypes[i] instanceof String) { + } else if (datatype instanceof String) { column.add(""); } } @@ -141,7 +143,7 @@ * @param variable the name of the data.frame in R. */ public RDataFrame(REngine engine, String[] names, - String[] rowNames, List<List<? extends Object>> data, + String[] rowNames, List<List<?>> data, String variable) { //Create the name ArrayList and fill it with the content of the name String[] String[] tempNames = {}; @@ -153,15 +155,11 @@ tempRowNames = rowNames.clone(); } this.names = new ArrayList<String>(); - for (int i = 0; i < tempNames.length; i++) { - this.names.add(tempNames[i]); - } + this.names.addAll(Arrays.asList(tempNames)); //Create the rowNames ArrayList and fill it with the content of the rowNames //String[] this.rowNames = new ArrayList<String>(); - for (int i = 0; i < tempRowNames.length; i++) { - this.rowNames.add(tempRowNames[i]); - } + this.rowNames.addAll(Arrays.asList(tempRowNames)); this.data = data; this.variable = variable; this.engine = engine; @@ -200,9 +198,7 @@ //Check if size is correct, if yes, modify local data. if (rowNamesArray.length <= this.data.get(0).size()) { this.rowNames.clear(); - for (int i = 0; i < rowNamesArray.length; i++) { - rowNames.add(rowNamesArray[i]); - } + rowNames.addAll(Arrays.asList(rowNamesArray)); return rowNames; } else { //if size is not correct, throw a RException. @@ -367,8 +363,8 @@ } if (!(this.rowNames.isEmpty())) { returnString += "row.names=c("; - for (int i = 0; i < rowNames.size(); i++) { - returnString += "\"" + rowNames.get(i) + "\","; + for (String rowName : rowNames) { + returnString += "\"" + rowName + "\","; } returnString = returnString.substring(0, returnString.length() - 1) + @@ -482,7 +478,7 @@ * * @return a ArrayList containing the ArrayLists of the R data.frame */ - public List<List<? extends Object>> getData() { + public List<List<?>> getData() { //TODO manage the autocommit mode here. return data; } @@ -494,9 +490,9 @@ * @param data * a ArrayList of ArrayLists, containing each ArrayList of the R * data.frame - * @throws RException + * @throws RException if an error occur while trying to assign the values */ - public void setData(List<List<? extends Object>> data) throws RException { + public void setData(List<List<?>> data) throws RException { this.data = data; engine.voidEval(toRString()); } @@ -525,7 +521,7 @@ if (data != null) { data.clear(); } else { - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); } if (attributes != null) { attributes.clear(); @@ -536,16 +532,12 @@ //update row names String[] rowNamesArray = (String[]) engine.eval(String.format( RInstructions.GET_ROW_NAMES, this.variable)); - for (int i = 0; i < rowNamesArray.length; i++) { - rowNames.add(rowNamesArray[i]); - } + rowNames.addAll(Arrays.asList(rowNamesArray)); //update names String[] namesArray = (String[]) engine.eval(String.format( RInstructions.GET_NAMES, this.variable)); - for (int i = 0; i < namesArray.length; i++) { - names.add(namesArray[i]); - } + names.addAll(Arrays.asList(namesArray)); //update data Integer dataframelength = (Integer) engine.eval(String.format( @@ -589,6 +581,7 @@ * the export. * @param names true/false to determine if the column names will be put on * the export. + * @throws IOException if cannot export to the outputFile */ public void exportCsv(File outputFile, boolean rowNames, boolean names) throws IOException { @@ -598,8 +591,8 @@ if (rowNames) { file.write(";"); } - for (int i = 0; i < this.names.size(); i++) { - file.write(this.names.get(i) + ";"); + for (String name : this.names) { + file.write(name + ";"); } file.newLine(); } @@ -608,8 +601,8 @@ if (rowNames) { file.write(this.rowNames.get(i) + ";"); } - for (int j = 0; j < this.data.size(); j++) { - file.write(this.data.get(j).get(i) + ";"); + for (List<?> aData : this.data) { + file.write(aData.get(i) + ";"); } file.newLine(); } @@ -628,12 +621,14 @@ * Does the csv file contains names of the rows. * @param names * Does the csv file contain names of the columns. + * @throws IOException + * If cannot read the inputFile */ public void importCsv(File inputFile, boolean rowNames, boolean names) - throws FileNotFoundException, IOException { + throws IOException { List<Object> tmp = new ArrayList<Object>(); tmp.add("string"); - importCsv(inputFile, rowNames, names, (List) tmp); + importCsv(inputFile, rowNames, names, tmp); } @@ -651,18 +646,20 @@ * @param importType * Object of the class of the data imported (all the data have * the same type). (Supported types : String, Double and Integer) + * @throws IOException + * if cannot read the inputFile */ public void importCsv(File inputFile, boolean rowNames, boolean names, - Object importType) throws FileNotFoundException, IOException { + Object importType) throws IOException { List<Object> tmp = new ArrayList<Object>(); if (importType instanceof String) { - tmp.add((String) importType); - importCsv(inputFile, rowNames, names, (List) tmp); + tmp.add(importType); + importCsv(inputFile, rowNames, names, tmp); } else if (importType instanceof Double) { - tmp.add((Double) importType); + tmp.add(importType); importCsv(inputFile, rowNames, names, tmp); } else if (importType instanceof Integer) { - tmp.add((Integer) importType); + tmp.add(importType); importCsv(inputFile, rowNames, names, tmp); } } @@ -683,12 +680,14 @@ * ArrayList of Object of the class of the data imported (the * ArrayList match the data type of the columns). (Supported * types : String, Double and Integer) + * @throws IOException + * if cannot read the inputFile */ public void importCsv(File inputFile, boolean rowNames, boolean names, - List<Object> importTypes) throws FileNotFoundException, IOException { + List<Object> importTypes) throws IOException { //temporary String to read lines. String tmp; - Integer dataSize = 0; + Integer dataSize; //get the first line of the file BufferedReader br = new BufferedReader(new FileReader(inputFile)); tmp = br.readLine(); @@ -715,14 +714,12 @@ this.names.clear(); } //get every name from the first line - for (int i = 1; i < splitted.length; i++) { - this.names.add(splitted[i]); - } + this.names.addAll(Arrays.asList(splitted).subList(1, splitted.length)); } //temporary data list. - List<List<? extends Object>> tempData = - new ArrayList<List<? extends Object>>(); + List<List<?>> tempData = + new ArrayList<List<?>>(); //Initialize all the data columns for (int i = 0; i < dataSize; i++) { @@ -740,14 +737,14 @@ this.rowNames.add(splitted[0]); index = 1; } - for (int i = 0 + index; i < splitted.length; i++) { + for (int i = index; i < splitted.length; i++) { //cast the data imported to the specified type. //test the size of the inputType list. If 1 import all the //columns as the type of the first element. if (importTypes.size() == 1) { if (importTypes.get(0) instanceof String) { ((ArrayList<Object>) tempData.get(i - index)).add( - (Serializable) splitted[i]); + splitted[i]); } else if (importTypes.get(0) instanceof Double) { ((ArrayList<Object>) tempData.get(i - index)).add(Double.valueOf( splitted[i])); @@ -758,7 +755,7 @@ } else if (importTypes.get(i - index) instanceof String) { ((ArrayList<Object>) tempData.get(i - index)).add( - (Serializable) splitted[i]); + splitted[i]); } else if (importTypes.get(i - index) instanceof Double) { ((ArrayList<Object>) tempData.get(i - index)).add(Double.valueOf( splitted[i])); @@ -806,4 +803,4 @@ return (new int[]{x,y}); } -} \ No newline at end of file +} Modified: trunk/src/main/java/org/nuiton/j2r/types/REXPAbstract.java =================================================================== --- trunk/src/main/java/org/nuiton/j2r/types/REXPAbstract.java 2010-04-12 12:15:23 UTC (rev 193) +++ trunk/src/main/java/org/nuiton/j2r/types/REXPAbstract.java 2010-04-14 09:51:16 UTC (rev 194) @@ -16,6 +16,7 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ package org.nuiton.j2r.types; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @@ -55,54 +56,52 @@ @Override public void setAttributes(Map<String, Object> attributes) throws RException { - //TODO should be useful to test the validity of attributes before - //assigning it. + //TODO should be useful to test the validity of attributes before assigning it. this.attributes = attributes; if ((this.attributes != null) && (!this.attributes.isEmpty())) { Set<String> keyset = attributes.keySet(); - String[] keys = keyset.toArray(new String[0]); - for (int i = 0; i < keys.length; i++) { + for (String key : keyset) { //foreach type of attribute, adapt the R instruction. - if (this.attributes.get(keys[i]) instanceof String) { + if (this.attributes.get(key) instanceof String) { engine.eval(String.format(RInstructions.SET_ATTRIBUTE, - this.variable, keys[i], - "\"" + this.attributes.get(keys[i]) + "\"")); - //String, value between quotes - } else if (this.attributes.get(keys[i]) instanceof Double) { + this.variable, key, + "\"" + this.attributes.get(key) + "\"")); + //String, value between quotes + } else if (this.attributes.get(key) instanceof Double) { engine.eval(String.format(RInstructions.SET_ATTRIBUTE, this.variable, - keys[i], this.attributes.get(keys[i]))); - } else if (this.attributes.get(keys[i]) instanceof Integer) { + key, this.attributes.get(key))); + } else if (this.attributes.get(key) instanceof Integer) { engine.eval(String.format(RInstructions.SET_ATTRIBUTE, this.variable, - keys[i], String.format(RInstructions.AS_INTEGER, - this.attributes.get(keys[i])))); - //Integer, value formated by the R function : as.integer() - } else if (this.attributes.get(keys[i]) instanceof Boolean) { - if ((Boolean) this.attributes.get(keys[i])) { + key, String.format(RInstructions.AS_INTEGER, + this.attributes.get(key)))); + //Integer, value formated by the R function : as.integer() + } else if (this.attributes.get(key) instanceof Boolean) { + if ((Boolean) this.attributes.get(key)) { engine.eval(String.format(RInstructions.SET_ATTRIBUTE, this.variable, - keys[i], RInstructions.TRUE)); - //Boolean true replaced by TRUE + key, RInstructions.TRUE)); + //Boolean true replaced by TRUE } else { engine.eval(String.format(RInstructions.SET_ATTRIBUTE, this.variable, - keys[i], RInstructions.FALSE)); - //Boolean false replaced by REPLACE + key, RInstructions.FALSE)); + //Boolean false replaced by REPLACE } - } else if (this.attributes.get(keys[i]) instanceof REXP) { + } else if (this.attributes.get(key) instanceof REXP) { engine.eval(String.format(RInstructions.SET_ATTRIBUTE, this.variable, - keys[i], - ((REXP) this.attributes.get(keys[i])).toRString())); - //REXP replaced by the result of their toRString() method. + key, + ((REXP) this.attributes.get(key)).toRString())); + //REXP replaced by the result of their toRString() method. } else { if (log.isWarnEnabled()) { - log.warn("This attribute is not valid : " + keys[i] + - " ; " + this.attributes.get(keys[i]) + + log.warn("This attribute is not valid : " + key + + " ; " + this.attributes.get(key) + ". It will not be sent to R"); - //if the attribute is not recognised. + //if the attribute is not recognised. } } } @@ -267,9 +266,7 @@ //Check if size is correct, if yes, modify local data. checkX(namesArray.length); this.names.clear(); - for (int i = 0; i < namesArray.length; i++) { - names.add(namesArray[i]); - } + names.addAll(Arrays.asList(namesArray)); return names; } else { @@ -323,7 +320,7 @@ * @throws org.nuiton.j2r.RException if the variable name have not been set. */ protected void checkVariable() throws RException { - if ((this.variable.equals("")) || (this.variable == null)) { + if ((this.variable == null) || (this.variable.equals(""))) { throw new RException( noVariable); } Modified: trunk/src/test/java/org/nuiton/j2r/DataframeTest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/DataframeTest.java 2010-04-12 12:15:23 UTC (rev 193) +++ trunk/src/test/java/org/nuiton/j2r/DataframeTest.java 2010-04-14 09:51:16 UTC (rev 194) @@ -51,11 +51,6 @@ engine.terminate(); } - /** - * This test data.frame creation method 1 and data assignment. - * - * @throws Exception - */ @Test public void testDataFrameCreationMethod1() throws Exception { /* @@ -85,7 +80,7 @@ column4.add(2); column4.add(3); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -108,32 +103,27 @@ dataframe1.setRowNames(rowNames); //Test data - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[1,1]")); - Assert.assertEquals(new Double(4.5), (Double) engine.eval("a[2,1]")); - Assert.assertEquals(new Double(0.01), (Double) engine.eval("a[3,1]")); - Assert.assertEquals("titi", (String) engine.eval("a[1,2]")); - Assert.assertEquals("tata", (String) engine.eval("a[2,2]")); - Assert.assertEquals("toto", (String) engine.eval("a[3,2]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[1,3]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[2,3]")); - Assert.assertEquals(false, (Boolean) engine.eval("a[3,3]")); - Assert.assertEquals(new Integer(1), (Integer) engine.eval("a[1,4]")); - Assert.assertEquals(new Integer(2), (Integer) engine.eval("a[2,4]")); - Assert.assertEquals(new Integer(3), (Integer) engine.eval("a[3,4]")); + Assert.assertEquals(3.0, engine.eval("a[1,1]")); + Assert.assertEquals(4.5, engine.eval("a[2,1]")); + Assert.assertEquals(0.01, engine.eval("a[3,1]")); + Assert.assertEquals("titi", engine.eval("a[1,2]")); + Assert.assertEquals("tata", engine.eval("a[2,2]")); + Assert.assertEquals("toto", engine.eval("a[3,2]")); + Assert.assertEquals(true, engine.eval("a[1,3]")); + Assert.assertEquals(true, engine.eval("a[2,3]")); + Assert.assertEquals(false, engine.eval("a[3,3]")); + Assert.assertEquals(1, engine.eval("a[1,4]")); + Assert.assertEquals(2, engine.eval("a[2,4]")); + Assert.assertEquals(3, engine.eval("a[3,4]")); //Test names - Assert.assertEquals("column1", (String) engine.eval("names(a)[1]")); - Assert.assertEquals("column2", (String) engine.eval("names(a)[2]")); + Assert.assertEquals("column1", engine.eval("names(a)[1]")); + Assert.assertEquals("column2", engine.eval("names(a)[2]")); //Test row names - Assert.assertEquals("row 1", (String) engine.eval("row.names(a)[1]")); - Assert.assertEquals("row 2", (String) engine.eval("row.names(a)[2]")); - Assert.assertEquals("row 3", (String) engine.eval("row.names(a)[3]")); + Assert.assertEquals("row 1", engine.eval("row.names(a)[1]")); + Assert.assertEquals("row 2", engine.eval("row.names(a)[2]")); + Assert.assertEquals("row 3", engine.eval("row.names(a)[3]")); } - /** - * This test data.frame creation method 2 and data assignment. - * - * @throws Exception - */ @Test public void testDataFrameCreationMethod2() throws Exception { /* @@ -141,24 +131,24 @@ * RDataFrame(REngine, Object[], int) + all setters */ - Object[] datatypes = { (Double)1.0, "a", (Boolean)true, (Integer)1 }; + Object[] datatypes = { 1.0, "a", true, 1 }; RDataFrame dataframe1 = new RDataFrame(engine, datatypes, 3); dataframe1.setVariable("a"); - dataframe1.set(0, 0, (Double)3.0); - dataframe1.set(0, 1, (Double)4.5); - dataframe1.set(0, 2, (Double)0.01); + dataframe1.set(0, 0, 3.0); + dataframe1.set(0, 1, 4.5); + dataframe1.set(0, 2, 0.01); dataframe1.set(1, 0, "titi"); dataframe1.set(1, 1, "tata"); dataframe1.set(1, 2, "toto"); - dataframe1.set(2, 0, (Boolean)true); - dataframe1.set(2, 1, (Boolean)true); - dataframe1.set(2, 2, (Boolean)false); - dataframe1.set(3, 0, (Integer)1); - dataframe1.set(3, 1, (Integer)2); - dataframe1.set(3, 2, (Integer)3); + dataframe1.set(2, 0, true); + dataframe1.set(2, 1, true); + dataframe1.set(2, 2, false); + dataframe1.set(3, 0, 1); + dataframe1.set(3, 1, 2); + dataframe1.set(3, 2, 3); List<String> names = new ArrayList<String>(); names.add("column1"); @@ -173,32 +163,27 @@ dataframe1.setRowNames(rowNames); //Test data - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[1,1]")); - Assert.assertEquals(new Double(4.5), (Double) engine.eval("a[2,1]")); - Assert.assertEquals(new Double(0.01), (Double) engine.eval("a[3,1]")); - Assert.assertEquals("titi", (String) engine.eval("a[1,2]")); - Assert.assertEquals("tata", (String) engine.eval("a[2,2]")); - Assert.assertEquals("toto", (String) engine.eval("a[3,2]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[1,3]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[2,3]")); - Assert.assertEquals(false, (Boolean) engine.eval("a[3,3]")); - Assert.assertEquals(new Integer(1), (Integer) engine.eval("a[1,4]")); - Assert.assertEquals(new Integer(2), (Integer) engine.eval("a[2,4]")); - Assert.assertEquals(new Integer(3), (Integer) engine.eval("a[3,4]")); + Assert.assertEquals(3.0, engine.eval("a[1,1]")); + Assert.assertEquals(4.5, engine.eval("a[2,1]")); + Assert.assertEquals(0.01, engine.eval("a[3,1]")); + Assert.assertEquals("titi", engine.eval("a[1,2]")); + Assert.assertEquals("tata", engine.eval("a[2,2]")); + Assert.assertEquals("toto", engine.eval("a[3,2]")); + Assert.assertEquals(true, engine.eval("a[1,3]")); + Assert.assertEquals(true, engine.eval("a[2,3]")); + Assert.assertEquals(false, engine.eval("a[3,3]")); + Assert.assertEquals(1, engine.eval("a[1,4]")); + Assert.assertEquals(2, engine.eval("a[2,4]")); + Assert.assertEquals(3, engine.eval("a[3,4]")); //Test names - Assert.assertEquals("column1", (String) engine.eval("names(a)[1]")); - Assert.assertEquals("column2", (String) engine.eval("names(a)[2]")); + Assert.assertEquals("column1", engine.eval("names(a)[1]")); + Assert.assertEquals("column2", engine.eval("names(a)[2]")); //Test row names - Assert.assertEquals("row 1", (String) engine.eval("row.names(a)[1]")); - Assert.assertEquals("row 2", (String) engine.eval("row.names(a)[2]")); - Assert.assertEquals("row 3", (String) engine.eval("row.names(a)[3]")); + Assert.assertEquals("row 1", engine.eval("row.names(a)[1]")); + Assert.assertEquals("row 2", engine.eval("row.names(a)[2]")); + Assert.assertEquals("row 3", engine.eval("row.names(a)[3]")); } - /** - * This test data.frame creation method 2 and data assignment. - * - * @throws Exception - */ @Test public void testDataFrameCreationMethod3() throws Exception { /* @@ -225,28 +210,26 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); - RDataFrame dataframe1 = new RDataFrame(engine, names, rowNames, data, - "a"); + new RDataFrame(engine, names, rowNames, data, "a"); //Test data - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[1,1]")); - Assert.assertEquals(new Double(4.5), (Double) engine.eval("a[2,1]")); - Assert.assertEquals(new Double(0.01), (Double) engine.eval("a[3,1]")); - Assert.assertEquals(new Double(1.0), (Double) engine.eval("a[1,2]")); - Assert.assertEquals(new Double(5555555555555555555555.0), - (Double) engine.eval("a[2,2]")); - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[3,2]")); + Assert.assertEquals(3.0, engine.eval("a[1,1]")); + Assert.assertEquals(4.5, engine.eval("a[2,1]")); + Assert.assertEquals(0.01, engine.eval("a[3,1]")); + Assert.assertEquals(1.0, engine.eval("a[1,2]")); + Assert.assertEquals(5555555555555555555555.0, engine.eval("a[2,2]")); + Assert.assertEquals(3.0, engine.eval("a[3,2]")); //Test names - Assert.assertEquals("column1", (String) engine.eval("names(a)[1]")); - Assert.assertEquals("column2", (String) engine.eval("names(a)[2]")); + Assert.assertEquals("column1", engine.eval("names(a)[1]")); + Assert.assertEquals("column2", engine.eval("names(a)[2]")); //Test row names - Assert.assertEquals("row 1", (String) engine.eval("row.names(a)[1]")); - Assert.assertEquals("row 2", (String) engine.eval("row.names(a)[2]")); - Assert.assertEquals("row 3", (String) engine.eval("row.names(a)[3]")); + Assert.assertEquals("row 1", engine.eval("row.names(a)[1]")); + Assert.assertEquals("row 2", engine.eval("row.names(a)[2]")); + Assert.assertEquals("row 3", engine.eval("row.names(a)[3]")); } @Test @@ -263,7 +246,7 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); @@ -303,7 +286,7 @@ //Test normally thrown exception when getting name(int) try { - String test = dataframe1.getName(2); + dataframe1.getName(2); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -311,7 +294,7 @@ //Test normally thrown exception when getting rowname(int) try { - String test = dataframe1.getRowName(3); + dataframe1.getRowName(3); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -335,7 +318,7 @@ //Test normally thrown exception when getting name(int) try { - String test = dataframe1.getRowName(3); + dataframe1.getRowName(3); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -368,18 +351,21 @@ //Modify the remote data.frame so we can test normally thrown exceptions //when getting names and row names - engine - .voidEval("a<-data.frame(a=c(1,2,3,4),b=c(4,5,6,7),d=c(7,8,9,10),row.names=c(\"a\",\"b\",\"c\",\"d\"))"); + engine.voidEval("a<-data.frame(" + + "a=c(1,2,3,4)," + + "b=c(4,5,6,7)," + + "d=c(7,8,9,10)," + + "row.names=c(\"a\",\"b\",\"c\",\"d\"))"); try { - List<String> test = dataframe1.getNames(); + dataframe1.getNames(); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } try { - List<String> test = dataframe1.getRowNames(); + dataframe1.getRowNames(); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -410,7 +396,7 @@ column4.add("toto"); column4.add("tata"); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -438,31 +424,31 @@ //Test exceptions normally thrown using getters try { - Object test = dataframe1.get(5, 7); + dataframe1.get(5, 7); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } try { - Object test = dataframe1.get(1, 7); + dataframe1.get(1, 7); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } try { - Object test = dataframe1.get(5, 1); + dataframe1.get(5, 1); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } //Test setters - dataframe1.set(0, 0, (Double)45.6); - dataframe1.set(1, 0, (Integer)45); - dataframe1.set(2, 0, (Boolean)false); - dataframe1.set(2, 2, (Boolean)true); + dataframe1.set(0, 0, 45.6); + dataframe1.set(1, 0, 45); + dataframe1.set(2, 0, false); + dataframe1.set(2, 2, true); dataframe1.set(3, 0, "tonton"); Assert.assertEquals(45.6, dataframe1.get(0, 0)); @@ -509,7 +495,7 @@ //Set a Double instead of Integer try { - dataframe1.set(1, 0, (Double)45.6); + dataframe1.set(1, 0, 45.6); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -517,7 +503,7 @@ //Set a Double instead of a Boolean try { - dataframe1.set(2, 0, (Double)45.6); + dataframe1.set(2, 0, 45.6); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -525,7 +511,7 @@ //Set a Double instead of a String try { - dataframe1.set(3, 0, (Double)45.6); + dataframe1.set(3, 0, 45.6); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -533,7 +519,7 @@ //Set an Integer instead of a Double try { - dataframe1.set(0, 0, (Integer)45); + dataframe1.set(0, 0, 45); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -541,7 +527,7 @@ //Set an Integer instead of a Boolean try { - dataframe1.set(2, 0, (Integer)45); + dataframe1.set(2, 0, 45); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -549,28 +535,28 @@ //Set an Integer instead of a String try { - dataframe1.set(3, 0, (Integer)45); + dataframe1.set(3, 0, 45); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } //Set a Boolean instead of a Double try { - dataframe1.set(0, 0, (Boolean)false); + dataframe1.set(0, 0, false); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } //Set a Boolean instead of an Integer try { - dataframe1.set(1, 0, (Boolean)false); + dataframe1.set(1, 0, false); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } //Set a Boolean instead of a String try { - dataframe1.set(3, 0, (Boolean)false); + dataframe1.set(3, 0, false); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } @@ -637,7 +623,7 @@ column4.add("toto"); column4.add("tata"); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -698,7 +684,7 @@ column4.add("toto"); column4.add("tata"); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -711,19 +697,19 @@ dataframe1.setAttribute("second_test_attribute", "second_value"); Assert.assertTrue((Boolean) engine.eval("is.data.frame(a)")); - Assert.assertEquals("test_value", (String) engine - .eval("attributes(a)$test_attribute")); - Assert.assertEquals("second_value", (String) engine - .eval("attributes(a)$second_test_attribute")); - Assert.assertEquals("test_value", dataframe1 - .getAttribute("test_attribute")); - Assert.assertEquals("second_value", dataframe1 - .getAttribute("second_test_attribute")); + Assert.assertEquals("test_value", + engine.eval("attributes(a)$test_attribute")); + Assert.assertEquals("second_value", + engine.eval("attributes(a)$second_test_attribute")); + Assert.assertEquals("test_value", + dataframe1.getAttribute("test_attribute")); + Assert.assertEquals("second_value", + dataframe1.getAttribute("second_test_attribute")); dataframe1.setAttribute("test_attribute", "third_value"); - Assert.assertEquals("third_value", (String) engine - .eval("attributes(a)$test_attribute")); + Assert.assertEquals("third_value", + engine.eval("attributes(a)$test_attribute")); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("attr1", "this is an attribute"); @@ -731,16 +717,16 @@ dataframe1.setAttributes(attributes); Assert.assertTrue((Boolean) engine.eval("is.data.frame(a)")); - Assert.assertEquals("this is an attribute", dataframe1 - .getAttribute("attr1")); - Assert.assertEquals("this is an attribute", dataframe1 - .getAttribute("attr1")); - Assert.assertEquals("this is another attribute", dataframe1 - .getAttribute("attr2")); - Assert.assertEquals("this is an attribute", dataframe1.getAttributes() - .get("attr1")); - Assert.assertEquals("this is another attribute", dataframe1 - .getAttributes().get("attr2")); + Assert.assertEquals("this is an attribute", + dataframe1.getAttribute("attr1")); + Assert.assertEquals("this is an attribute", + dataframe1.getAttribute("attr1")); + Assert.assertEquals("this is another attribute", + dataframe1.getAttribute("attr2")); + Assert.assertEquals("this is an attribute", + dataframe1.getAttributes().get("attr1")); + Assert.assertEquals("this is another attribute", + dataframe1.getAttributes().get("attr2")); try { dataframe1.getAttribute("toto"); @@ -775,7 +761,7 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); @@ -789,8 +775,7 @@ testDataFrame.exportCsv(new File("/tmp/test.csv"), true, true); RDataFrame dataframe2 = new RDataFrame(engine); - dataframe2.importCsv(new File("/tmp/test.csv"), true, true, new Double( - 3.0)); + dataframe2.importCsv(new File("/tmp/test.csv"), true, true, 3.0); dataframe2.setVariable("a"); //Test import with same type for each column (String). @@ -814,7 +799,7 @@ column6.add("tata"); column6.add("toto"); - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); data.add(column5); data.add(column6); @@ -861,7 +846,7 @@ column8.add(5); column8.add(6); - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); data.add(column7); data.add(column8); @@ -914,15 +899,15 @@ column4.add("blabla"); column4.add("blablabla"); - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); data.add(column1); data.add(column3); data.add(column4); List<Object> types = new ArrayList<Object>(); - types.add(new Double(4.0)); - types.add(new Integer(4)); - types.add(new String()); + types.add(4.0); + types.add(4); + types.add(""); testDataFrame = new RDataFrame(engine); try { @@ -938,17 +923,12 @@ dataframe3.setVariable("a"); //Test data - Assert - .assertEquals(new Double(3.0), dataframe3.getData().get(0).get( - 0)); - Assert - .assertEquals(new Double(4.5), dataframe3.getData().get(0).get( - 1)); - Assert.assertEquals(new Double(0.01), dataframe3.getData().get(0) - .get(2)); - Assert.assertEquals(new Integer(1), dataframe3.getData().get(1).get(0)); - Assert.assertEquals(new Integer(5), dataframe3.getData().get(1).get(1)); - Assert.assertEquals(new Integer(3), dataframe3.getData().get(1).get(2)); + Assert.assertEquals(3.0, dataframe3.getData().get(0).get(0)); + Assert.assertEquals(4.5, dataframe3.getData().get(0).get(1)); + Assert.assertEquals(0.01, dataframe3.getData().get(0).get(2)); + Assert.assertEquals(1, dataframe3.getData().get(1).get(0)); + Assert.assertEquals(5, dataframe3.getData().get(1).get(1)); + Assert.assertEquals(3, dataframe3.getData().get(1).get(2)); Assert.assertEquals("bla", dataframe3.getData().get(2).get(0)); Assert.assertEquals("blabla", dataframe3.getData().get(2).get(1)); Assert.assertEquals("blablabla", dataframe3.getData().get(2).get(2)); @@ -990,8 +970,13 @@ @Test public void testGetFrom() throws Exception { - engine - .voidEval("a<-data.frame(column1=c(3.0,4.5,0.01),column2=c(as.integer(1),as.integer(5),as.integer(3)),column3=c(TRUE,TRUE,FALSE),column4=c(\"bla\",\"blabla\",\"blablabla\"),row.names=c(\"row 1\",\"row 2\",\"row 3\"),stringsAsFactors=FALSE)"); + engine.voidEval("a<-data.frame(" + + "column1=c(3.0,4.5,0.01)," + + "column2=c(as.integer(1),as.integer(5),as.integer(3))," + + "column3=c(TRUE,TRUE,FALSE)," + + "column4=c(\"bla\",\"blabla\",\"blablabla\")," + + "row.names=c(\"row 1\",\"row 2\",\"row 3\")," + + "stringsAsFactors=FALSE)"); RDataFrame dataframe1 = new RDataFrame(engine); dataframe1.getFrom("a"); @@ -1023,11 +1008,6 @@ Assert.assertEquals("row 3", dataframe1.getRowNames().get(2)); } - /** - * This test data.frame creation method 1 and data assignment. - * - * @throws Exception - */ @Test public void testDataFrameCreationMethod1WithoutAutoCommit() throws Exception { @@ -1059,7 +1039,7 @@ column4.add(2); column4.add(3); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -1085,32 +1065,27 @@ engine.setAutoCommit(true); //Test data - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[1,1]")); - Assert.assertEquals(new Double(4.5), (Double) engine.eval("a[2,1]")); - Assert.assertEquals(new Double(0.01), (Double) engine.eval("a[3,1]")); - Assert.assertEquals("titi", (String) engine.eval("a[1,2]")); - Assert.assertEquals("tata", (String) engine.eval("a[2,2]")); - Assert.assertEquals("toto", (String) engine.eval("a[3,2]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[1,3]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[2,3]")); - Assert.assertEquals(false, (Boolean) engine.eval("a[3,3]")); - Assert.assertEquals(new Integer(1), (Integer) engine.eval("a[1,4]")); - Assert.assertEquals(new Integer(2), (Integer) engine.eval("a[2,4]")); - Assert.assertEquals(new Integer(3), (Integer) engine.eval("a[3,4]")); + Assert.assertEquals(3.0, engine.eval("a[1,1]")); + Assert.assertEquals(4.5, engine.eval("a[2,1]")); + Assert.assertEquals(0.01, engine.eval("a[3,1]")); + Assert.assertEquals("titi", engine.eval("a[1,2]")); + Assert.assertEquals("tata", engine.eval("a[2,2]")); + Assert.assertEquals("toto", engine.eval("a[3,2]")); + Assert.assertEquals(true, engine.eval("a[1,3]")); + Assert.assertEquals(true, engine.eval("a[2,3]")); + Assert.assertEquals(false, engine.eval("a[3,3]")); + Assert.assertEquals(1, engine.eval("a[1,4]")); + Assert.assertEquals(2, engine.eval("a[2,4]")); + Assert.assertEquals(3, engine.eval("a[3,4]")); //Test names - Assert.assertEquals("column1", (String) engine.eval("names(a)[1]")); - Assert.assertEquals("column2", (String) engine.eval("names(a)[2]")); + Assert.assertEquals("column1", engine.eval("names(a)[1]")); + Assert.assertEquals("column2", engine.eval("names(a)[2]")); //Test row names - Assert.assertEquals("row 1", (String) engine.eval("row.names(a)[1]")); - Assert.assertEquals("row 2", (String) engine.eval("row.names(a)[2]")); - Assert.assertEquals("row 3", (String) engine.eval("row.names(a)[3]")); + Assert.assertEquals("row 1", engine.eval("row.names(a)[1]")); + Assert.assertEquals("row 2", engine.eval("row.names(a)[2]")); + Assert.assertEquals("row 3", engine.eval("row.names(a)[3]")); } - /** - * This test data.frame creation method 2 and data assignment. - * - * @throws Exception - */ @Test public void testDataFrameCreationMethod2WithoutAutoCommit() throws Exception { @@ -1155,32 +1130,27 @@ engine.setAutoCommit(true); //Test data - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[1,1]")); - Assert.assertEquals(new Double(4.5), (Double) engine.eval("a[2,1]")); - Assert.assertEquals(new Double(0.01), (Double) engine.eval("a[3,1]")); - Assert.assertEquals("titi", (String) engine.eval("a[1,2]")); - Assert.assertEquals("tata", (String) engine.eval("a[2,2]")); - Assert.assertEquals("toto", (String) engine.eval("a[3,2]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[1,3]")); - Assert.assertEquals(true, (Boolean) engine.eval("a[2,3]")); - Assert.assertEquals(false, (Boolean) engine.eval("a[3,3]")); - Assert.assertEquals(new Integer(1), (Integer) engine.eval("a[1,4]")); - Assert.assertEquals(new Integer(2), (Integer) engine.eval("a[2,4]")); - Assert.assertEquals(new Integer(3), (Integer) engine.eval("a[3,4]")); + Assert.assertEquals(3.0, engine.eval("a[1,1]")); + Assert.assertEquals(4.5, engine.eval("a[2,1]")); + Assert.assertEquals(0.01, engine.eval("a[3,1]")); + Assert.assertEquals("titi", engine.eval("a[1,2]")); + Assert.assertEquals("tata", engine.eval("a[2,2]")); + Assert.assertEquals("toto", engine.eval("a[3,2]")); + Assert.assertEquals(true, engine.eval("a[1,3]")); + Assert.assertEquals(true, engine.eval("a[2,3]")); + Assert.assertEquals(false, engine.eval("a[3,3]")); + Assert.assertEquals(1, engine.eval("a[1,4]")); + Assert.assertEquals(2, engine.eval("a[2,4]")); + Assert.assertEquals(3, engine.eval("a[3,4]")); //Test names - Assert.assertEquals("column1", (String) engine.eval("names(a)[1]")); - Assert.assertEquals("column2", (String) engine.eval("names(a)[2]")); + Assert.assertEquals("column1", engine.eval("names(a)[1]")); + Assert.assertEquals("column2", engine.eval("names(a)[2]")); //Test row names - Assert.assertEquals("row 1", (String) engine.eval("row.names(a)[1]")); - Assert.assertEquals("row 2", (String) engine.eval("row.names(a)[2]")); - Assert.assertEquals("row 3", (String) engine.eval("row.names(a)[3]")); + Assert.assertEquals("row 1", engine.eval("row.names(a)[1]")); + Assert.assertEquals("row 2", engine.eval("row.names(a)[2]")); + Assert.assertEquals("row 3", engine.eval("row.names(a)[3]")); } - /** - * This test data.frame creation method 2 and data assignment. - * - * @throws Exception - */ @Test public void testDataFrameCreationMethod3WithoutAutoCommit() throws Exception { @@ -1210,31 +1180,29 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); - RDataFrame dataframe1 = new RDataFrame(engine, names, rowNames, data, - "a"); + new RDataFrame(engine, names, rowNames, data, "a"); engine.commit(); engine.setAutoCommit(true); //Test data - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[1,1]")); - Assert.assertEquals(new Double(4.5), (Double) engine.eval("a[2,1]")); - Assert.assertEquals(new Double(0.01), (Double) engine.eval("a[3,1]")); - Assert.assertEquals(new Double(1.0), (Double) engine.eval("a[1,2]")); - Assert.assertEquals(new Double(5555555555555555555555.0), - (Double) engine.eval("a[2,2]")); - Assert.assertEquals(new Double(3.0), (Double) engine.eval("a[3,2]")); + Assert.assertEquals(3.0, engine.eval("a[1,1]")); + Assert.assertEquals(4.5, engine.eval("a[2,1]")); + Assert.assertEquals(0.01, engine.eval("a[3,1]")); + Assert.assertEquals(1.0, engine.eval("a[1,2]")); + Assert.assertEquals(5555555555555555555555.0, engine.eval("a[2,2]")); + Assert.assertEquals(3.0, engine.eval("a[3,2]")); //Test names - Assert.assertEquals("column1", (String) engine.eval("names(a)[1]")); - Assert.assertEquals("column2", (String) engine.eval("names(a)[2]")); + Assert.assertEquals("column1", engine.eval("names(a)[1]")); + Assert.assertEquals("column2", engine.eval("names(a)[2]")); //Test row names - Assert.assertEquals("row 1", (String) engine.eval("row.names(a)[1]")); - Assert.assertEquals("row 2", (String) engine.eval("row.names(a)[2]")); - Assert.assertEquals("row 3", (String) engine.eval("row.names(a)[3]")); + Assert.assertEquals("row 1", engine.eval("row.names(a)[1]")); + Assert.assertEquals("row 2", engine.eval("row.names(a)[2]")); + Assert.assertEquals("row 3", engine.eval("row.names(a)[3]")); } @Test @@ -1254,7 +1222,7 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); @@ -1294,7 +1262,7 @@ //Test normally thrown exception when getting name(int) try { - String test = dataframe1.getName(2); + dataframe1.getName(2); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -1302,7 +1270,7 @@ //Test normally thrown exception when getting rowname(int) try { - String test = dataframe1.getRowName(3); + dataframe1.getRowName(3); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -1326,7 +1294,7 @@ //Test normally thrown exception when getting name(int) try { - String test = dataframe1.getRowName(3); + dataframe1.getRowName(3); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); @@ -1386,7 +1354,7 @@ column4.add("toto"); column4.add("tata"); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -1414,31 +1382,31 @@ //Test exceptions normally thrown using getters try { - Object test = dataframe1.get(5, 7); + dataframe1.get(5, 7); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } try { - Object test = dataframe1.get(1, 7); + dataframe1.get(1, 7); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } try { - Object test = dataframe1.get(5, 1); + dataframe1.get(5, 1); Assert.fail("Error was not thrown although it should have been"); } catch (IndexOutOfBoundsException eee) { log.debug("Exception normally thrown ", eee); } //Test setters - dataframe1.set(0, 0, (Double)45.6); - dataframe1.set(1, 0, (Integer)45); - dataframe1.set(2, 0, (Boolean)false); - dataframe1.set(2, 2, (Boolean)true); + dataframe1.set(0, 0, 45.6); + dataframe1.set(1, 0, 45); + dataframe1.set(2, 0, false); + dataframe1.set(2, 2, true); dataframe1.set(3, 0, "tonton"); Assert.assertEquals(45.6, dataframe1.get(0, 0)); @@ -1485,7 +1453,7 @@ //Set a Double instead of Integer try { - dataframe1.set(1, 0, (Double)45.6); + dataframe1.set(1, 0, 45.6); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -1493,7 +1461,7 @@ //Set a Double instead of a Boolean try { - dataframe1.set(2, 0, (Double)45.6); + dataframe1.set(2, 0, 45.6); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -1501,7 +1469,7 @@ //Set a Double instead of a String try { - dataframe1.set(3, 0, (Double)45.6); + dataframe1.set(3, 0, 45.6); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -1509,7 +1477,7 @@ //Set an Integer instead of a Double try { - dataframe1.set(0, 0, (Integer)45); + dataframe1.set(0, 0, 45); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -1517,7 +1485,7 @@ //Set an Integer instead of a Boolean try { - dataframe1.set(2, 0, (Integer)45); + dataframe1.set(2, 0, 45); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { log.debug("Exception normally thrown ", eee); @@ -1525,28 +1493,28 @@ //Set an Integer instead of a String try { - dataframe1.set(3, 0, (Integer)45); + dataframe1.set(3, 0, 45); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } //Set a Boolean instead of a Double try { - dataframe1.set(0, 0, (Boolean)false); + dataframe1.set(0, 0, false); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } //Set a Boolean instead of an Integer try { - dataframe1.set(1, 0, (Boolean)false); + dataframe1.set(1, 0, false); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } //Set a Boolean instead of a String try { - dataframe1.set(3, 0, (Boolean)false); + dataframe1.set(3, 0, false); Assert.fail("Error was not thrown although it should have been"); } catch (RException eee) { } @@ -1618,7 +1586,7 @@ column4.add("toto"); column4.add("tata"); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -1681,7 +1649,7 @@ column4.add("toto"); column4.add("tata"); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); data.add(column3); @@ -1695,22 +1663,22 @@ engine.setAutoCommit(true); Assert.assertTrue((Boolean) engine.eval("is.data.frame(a)")); - Assert.assertEquals("test_value", (String) engine - .eval("attributes(a)$test_attribute")); - Assert.assertEquals("second_value", (String) engine - .eval("attributes(a)$second_test_attribute")); + Assert.assertEquals("test_value", + engine.eval("attributes(a)$test_attribute")); + Assert.assertEquals("second_value", + engine.eval("attributes(a)$second_test_attribute")); engine.setAutoCommit(false); - Assert.assertEquals("test_value", dataframe1 - .getAttribute("test_attribute")); - Assert.assertEquals("second_value", dataframe1 - .getAttribute("second_test_attribute")); + Assert.assertEquals("test_value", + dataframe1.getAttribute("test_attribute")); + Assert.assertEquals("second_value", + dataframe1.getAttribute("second_test_attribute")); dataframe1.setAttribute("test_attribute", "third_value"); engine.setAutoCommit(true); Assert.assertTrue((Boolean) engine.eval("is.data.frame(a)")); - Assert.assertEquals("third_value", (String) engine - .eval("attributes(a)$test_attribute")); + Assert.assertEquals("third_value", + engine.eval("attributes(a)$test_attribute")); engine.setAutoCommit(false); Map<String, Object> attributes = new HashMap<String, Object>(); @@ -1719,16 +1687,16 @@ dataframe1.setAttributes(attributes); Assert.assertTrue((Boolean) engine.eval("is.data.frame(a)")); - Assert.assertEquals("this is an attribute", dataframe1 - .getAttribute("attr1")); - Assert.assertEquals("this is an attribute", dataframe1 - .getAttribute("attr1")); - Assert.assertEquals("this is another attribute", dataframe1 - .getAttribute("attr2")); - Assert.assertEquals("this is an attribute", dataframe1.getAttributes() - .get("attr1")); - Assert.assertEquals("this is another attribute", dataframe1 - .getAttributes().get("attr2")); + Assert.assertEquals("this is an attribute", + dataframe1.getAttribute("attr1")); + Assert.assertEquals("this is an attribute", + dataframe1.getAttribute("attr1")); + Assert.assertEquals("this is another attribute", + dataframe1.getAttribute("attr2")); + Assert.assertEquals("this is an attribute", + dataframe1.getAttributes().get("attr1")); + Assert.assertEquals("this is another attribute", + dataframe1.getAttributes().get("attr2")); engine.setAutoCommit(true); } @@ -1756,7 +1724,7 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); @@ -1770,8 +1738,7 @@ testDataFrame.exportCsv(new File("/tmp/test.csv"), true, true); RDataFrame dataframe2 = new RDataFrame(engine); - dataframe2.importCsv(new File("/tmp/test.csv"), true, true, new Double( - 3.0)); + dataframe2.importCsv(new File("/tmp/test.csv"), true, true, 3.0); dataframe2.setVariable("a"); //Test data @@ -1810,7 +1777,7 @@ column6.add("tata"); column6.add("toto"); - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); data.add(column5); data.add(column6); @@ -1857,7 +1824,7 @@ column8.add(5); column8.add(6); - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); data.add(column7); data.add(column8); @@ -1910,15 +1877,15 @@ column4.add("blabla"); column4.add("blablabla"); - data = new ArrayList<List<? extends Object>>(); + data = new ArrayList<List<?>>(); data.add(column1); data.add(column3); data.add(column4); List<Object> types = new ArrayList<Object>(); - types.add(new Double(4.0)); - types.add(new Integer(4)); - types.add(new String()); + types.add(4.0); + types.add(4); + types.add(""); testDataFrame = new RDataFrame(engine); try { @@ -1934,12 +1901,12 @@ dataframe3.setVariable("a"); //Test data - Assert.assertEquals(new Double(3.0), dataframe3.get(0, 0)); - Assert.assertEquals(new Double(4.5), dataframe3.get(0, 1)); - Assert.assertEquals(new Double(0.01), dataframe3.get(0, 2)); - Assert.assertEquals(new Integer(1), dataframe3.get(1, 0)); - Assert.assertEquals(new Integer(5), dataframe3.get(1, 1)); - Assert.assertEquals(new Integer(3), dataframe3.get(1, 2)); + Assert.assertEquals(3.0, dataframe3.get(0, 0)); + Assert.assertEquals(4.5, dataframe3.get(0, 1)); + Assert.assertEquals(0.01, dataframe3.get(0, 2)); + Assert.assertEquals(1, dataframe3.get(1, 0)); + Assert.assertEquals(5, dataframe3.get(1, 1)); + Assert.assertEquals(3, dataframe3.get(1, 2)); Assert.assertEquals("bla", dataframe3.get(2, 0)); Assert.assertEquals("blabla", dataframe3.get(2, 1)); Assert.assertEquals("blablabla", dataframe3.get(2, 2)); @@ -2000,11 +1967,11 @@ column2.add(5555555555555555555555.0); column2.add(3.0); - List<List<? extends Object>> data = new ArrayList<List<? extends Object>>(); + List<List<?>> data = new ArrayList<List<?>>(); data.add(column1); data.add(column2); - RDataFrame testDataFrame = new RDataFrame(engine); + RDataFrame testDataFrame; try { testDataFrame = new RDataFrame(engine, names, rowNames, data, "test"); Modified: trunk/src/test/java/org/nuiton/j2r/ListTest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/ListTest.java 2010-04-12 12:15:23 UTC (rev 193) +++ trunk/src/test/java/org/nuiton/j2r/ListTest.java 2010-04-14 09:51:16 UTC (rev 194) @@ -242,12 +242,6 @@ data.add(3.6); data.add(true); - List<String> names = new ArrayList<String>(); - names.add("a"); - names.add("b"); - names.add("c"); - names.add("d"); - RList list1 = new RList(engine); list1.setVariable("a"); list1.setData(data); @@ -689,12 +683,6 @@ data.add(3.6); data.add(true); - List<String> names = new ArrayList<String>(); - names.add("a"); - names.add("b"); - names.add("c"); - names.add("d"); - RList list1 = new RList(engine); list1.setVariable("a"); list1.setData(data); @@ -721,12 +709,6 @@ data.add(3.6); data.add(true); - List<String> names = new ArrayList<String>(); - names.add("a"); - names.add("b"); - names.add("c"); - names.add("d"); - RList list1 = new RList(engine); list1.setVariable("a"); list1.setData(data); @@ -895,8 +877,8 @@ Assert.assertEquals(false, list1.getAttribute("booleanFalseAttribute")); list1.setAttribute("test_attribute", "third_value"); - Assert.assertEquals("third_value", (String) engine - .eval("attributes(a)$test_attribute")); + Assert.assertEquals("third_value", + engine.eval("attributes(a)$test_attribute")); try { list1.getAttribute("toto"); @@ -922,14 +904,14 @@ attributes.put("booleanFalseAttribute", false); list1.setAttributes(attributes); - Assert.assertEquals("test_value", list1.getAttributes().get( - "stringAttribute")); + Assert.assertEquals("test_value", + list1.getAttributes().get("stringAttribute")); Assert.assertEquals(3.6, list1.getAttributes().get("doubleAttribute")); Assert.assertEquals(3, list1.getAttributes().get("integerAttribute")); - Assert.assertEquals(true, list1.getAttributes().get( - "booleanTrueAttribute")); - Assert.assertEquals(false, list1.getAttributes().get( - "booleanFalseAttribute")); + Assert.assertEquals(true, + list1.getAttributes().get("booleanTrueAttribute")); + Assert.assertEquals(false, + list1.getAttributes().get("booleanFalseAttribute")); engine.setAutoCommit(true); } Modified: trunk/src/test/java/org/nuiton/j2r/NetTest.java =================================================================== --- trunk/src/test/java/org/nuiton/j2r/NetTest.java 2010-04-12 12:15:23 UTC (rev 193) +++ trunk/src/test/java/org/nuiton/j2r/NetTest.java 2010-04-14 09:51:16 UTC (rev 194) @@ -240,9 +240,7 @@ engine.saveRData(workingdir); engine.remove("a"); engine.loadRData(workingdir); - Double testDouble = (Double) engine.eval("a"); - Double compareTo = new Double(5.0); - Assert.assertEquals(compareTo, testDouble); + Assert.assertEquals(5.0, engine.eval("a")); } @Test @@ -256,9 +254,7 @@ engine.dput("a", "testDputDgetfile"); engine.remove("a"); engine.dget("a", "testDputDgetfile"); - Double testDouble = (Double) engine.eval("a"); - Double compareTo = new Double(5.0); - Assert.assertEquals(compareTo, testDouble); + Assert.assertEquals(5.0, engine.eval("a")); workingdir = new File("/"); //test method using absolute path @@ -267,9 +263,7 @@ engine.dput("a", testingFile); engine.remove("a"); engine.dget("a", testingFile); - Double testDouble2 = (Double) engine.eval("a"); - Double compareTo2 = new Double(6.0); - Assert.assertEquals(compareTo2, testDouble2); + Assert.assertEquals(6.0, engine.eval("a")); File testWorkingDirectory = engine.getwd(); Assert.assertEquals(workingdir.getAbsolutePath(), testWorkingDirectory.getAbsolutePath()); @@ -278,7 +272,7 @@ @Test public void testRemove() throws Exception { engine.voidEval("a<-6.0"); - Assert.assertEquals(new Double(6.0), engine.eval("a")); + Assert.assertEquals(6.0, engine.eval("a")); engine.remove("a"); Assert.assertFalse((Boolean) engine.eval("exists(\"a\")")); } @@ -289,7 +283,7 @@ engine.voidEval("a<-5.0"); engine.remove("b"); engine.mv("a", "b"); - Assert.assertEquals(new Double(5.0), engine.eval("b")); + Assert.assertEquals(5.0, engine.eval("b")); Assert.assertFalse((Boolean) engine.eval("exists(\"a\")")); } @@ -320,11 +314,11 @@ engine.voidEval("e<-5.0"); engine.voidEval("f<-5.0"); engine.commit(); - Assert.assertEquals(new Double(10.0), engine.eval("a")); - Assert.assertEquals(new Double(5.0), engine.eval("b")); - Assert.assertEquals(new Double(5.0), engine.eval("d")); - Assert.assertEquals(new Double(5.0), engine.eval("e")); - Assert.assertEquals(new Double(5.0), engine.eval("f")); + Assert.assertEquals(10.0, engine.eval("a")); + Assert.assertEquals(5.0, engine.eval("b")); + Assert.assertEquals(5.0, engine.eval("d")); + Assert.assertEquals(5.0, engine.eval("e")); + Assert.assertEquals(5.0, engine.eval("f")); } @Test
participants (1)
-
jcouteau@users.nuiton.org