[LutinJ2R-commits] r117 - trunk/src/main/java/org/nuiton/j2r/types
Author: jcouteau Date: 2009-07-31 11:18:50 +0200 (Fri, 31 Jul 2009) New Revision: 117 Modified: trunk/src/main/java/org/nuiton/j2r/types/RList.java Log: Refactor and add some javadoc Modified: trunk/src/main/java/org/nuiton/j2r/types/RList.java =================================================================== --- trunk/src/main/java/org/nuiton/j2r/types/RList.java 2009-07-30 14:05:04 UTC (rev 116) +++ trunk/src/main/java/org/nuiton/j2r/types/RList.java 2009-07-31 09:18:50 UTC (rev 117) @@ -20,26 +20,37 @@ import java.util.HashMap; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.nuiton.j2r.REngine; import org.nuiton.j2r.RException; public class RList extends REXPAbstract implements REXP { - - private Log log = LogFactory.getLog(RList.class); + //List of the names for each element of the list in R. private List<String> names; + //Content of the list (eg elements of the list in R) private List<Object> data; + //R instruction to assign names private String setNamesString = "names(%s)<-c(%s)"; + //R instruction to assign one name private String setNameString = "names(%s)[%s]<-\"%s\""; + //R instruction to get the names private String getNamesString = "names(%s)"; + //R instruction to get one name private String getNameString = "names(%s)[%s]"; + //Default error message if indexOutOfBoundException. private String indexExceptionText = "Cannot perform operation, index is superior to size.\nIndex : %s\nSize : %s"; + //Default error message if inconsistency between local and distant data. private String dataInconsistencyText = "There is an inconsistency between the local and distant data.\nLocal data size : %s\nDistant data size : %s"; + //Default error if no variable name given. private String noVariable = "No variable name given"; + /** + * Create a default RList linked to a R engine (the List is not initialized + * in R.) + * + * @param engine the R engine in which to assign the RList. + */ public RList(REngine engine) { super(); this.names = new ArrayList<String>(); @@ -49,6 +60,16 @@ this.attributes = new HashMap<String, Object>(); } + /** + * Create the RList with parameters and initialize it in R. + * + * @param names the names of each object of the list. + * @param data the list of the objects that compound the RList. + * @param engine the R engine in which to assign the RList. + * @param variable the variable name in R. + * @throws org.nuiton.j2r.RException if an error occur while initializing + * the list in R. + */ public RList(List<String> names, List<Object> data, REngine engine, String variable) throws RException { super(); @@ -258,13 +279,12 @@ } if (data.get(i) instanceof String) { returnString += "\"" + data.get(i) + "\","; - } else if (data.get(i) instanceof Boolean) { - if ((Boolean) data.get(i)) { - returnString += "TRUE,"; - } else { - returnString += "FALSE,"; - } - + } else if ((data.get(i) instanceof Boolean) && ((Boolean) data. + get(i))) { + returnString += "TRUE,"; + } else if ((data.get(i) instanceof Boolean) && (!(Boolean) data. + get(i))) { + returnString += "FALSE,"; } else if (data.get(i) instanceof Integer) { returnString += "as.integer(" + data.get(i) + "),"; } else if (data.get(i) instanceof REXP) { @@ -274,10 +294,8 @@ } } returnString = returnString.substring(0, returnString.length() - 1); - returnString += ")"; - } else { - returnString += ")"; } + returnString += ")"; return returnString; } @@ -545,7 +563,13 @@ } } - public void testVariable() throws RException { + /** + * Test that the variable name has been set so that the list can be sent to + * R. + * + * @throws org.nuiton.j2r.RException if the variable name have not been set. + */ + private void testVariable() throws RException { if ((this.variable.equals("")) || (this.variable == null)) { throw new RException( noVariable);
participants (1)
-
jcouteau@users.labs.libre-entreprise.org