Skip to content

Commit

Permalink
stringbuffer type changed to stringbuilder in private code of RCode
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytecode committed Aug 28, 2020
1 parent ad74e2f commit cf8e0ab
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
8 changes: 0 additions & 8 deletions RCaller/.classpath

This file was deleted.

2 changes: 1 addition & 1 deletion RCaller/src/main/java/com/github/rcaller/JavaObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setName(String name) {

public static String ConvertToRCode(String name, Object javaobject, boolean useList, boolean useEquals) throws IllegalAccessException {
StringBuilder builder = new StringBuilder();
StringBuffer tempbuffer = new StringBuffer();
StringBuilder tempbuffer = new StringBuilder();
String className, varName;
Object o;
Field f;
Expand Down
16 changes: 11 additions & 5 deletions RCaller/src/main/java/com/github/rcaller/rstuff/RCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

public class RCode {

private StringBuffer code;
private StringBuilder code;
private TempFileService tempFileService = null;


private RCode() {
this.code = new StringBuffer();
this.code = new StringBuilder();
}

public static RCode create() {
Expand All @@ -56,17 +56,23 @@ public static RCode create() {
public static RCode create(StringBuffer stringBuffer) {
RCode rCode = RCode.create();
rCode.clear();
rCode.getCode().append(stringBuffer);
rCode.getCode().append(stringBuffer.toString());
return rCode;
}

public void setCode(StringBuffer sb) {
this.code = new StringBuffer();
this.code = new StringBuilder();
clear();
this.code.append(sb.toString());
}

public void setCode(StringBuilder sb) {
this.code = new StringBuilder();
clear();
this.code.append(sb);
}

public StringBuffer getCode() {
public StringBuilder getCode() {
return (this.code);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Object eval(Reader reader, Bindings bindings) throws ScriptException {
@Override
public void put(String name, Object o) {
rcode.clearOnline();
StringBuffer code = new StringBuffer();
StringBuilder code = new StringBuilder();
RCodeUtils.addRespectToType(code, name, o, false);
rcode.addRCode("result <- list(a=0)");
rcode.setCode(code);
Expand Down
40 changes: 20 additions & 20 deletions RCaller/src/main/java/com/github/rcaller/util/RCodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@

public class RCodeUtils {

public static void addIntArray(StringBuffer rCode, String name, int[] arr, boolean useEquals) {
public static void addIntArray(StringBuilder rCode, String name, int[] arr, boolean useEquals) {
addArray(rCode, name, ArrayUtils.toObject(arr), useEquals, false);
}

public static void addLongArray(StringBuffer rCode, String name, long[] arr, boolean useEquals) {
public static void addLongArray(StringBuilder rCode, String name, long[] arr, boolean useEquals) {
addArray(rCode, name, ArrayUtils.toObject(arr), useEquals, false);
}

public static void addFloatArray(StringBuffer rCode, String name, float[] arr, boolean useEquals) {
public static void addFloatArray(StringBuilder rCode, String name, float[] arr, boolean useEquals) {
addArray(rCode, name, ArrayUtils.toObject(arr), useEquals, false);
}

public static void addDoubleArray(StringBuffer rCode, String name, double[] arr, boolean useEquals) {
public static void addDoubleArray(StringBuilder rCode, String name, double[] arr, boolean useEquals) {
addArray(rCode, name, ArrayUtils.toObject(arr), useEquals, false);
}

public static void addStringArray(StringBuffer rCode, String name, String[] arr, boolean useEquals) {
public static void addStringArray(StringBuilder rCode, String name, String[] arr, boolean useEquals) {
addArray(rCode, name, arr, useEquals, true);
}

public static void addShortArray(StringBuffer rCode, String name, short[] arr, boolean useEquals) {
public static void addShortArray(StringBuilder rCode, String name, short[] arr, boolean useEquals) {
addArray(rCode, name, ArrayUtils.toObject(arr), useEquals, false);
}

public static void addLogicalArray(StringBuffer rCode, String name, boolean[] arr, boolean useEquals) {
public static void addLogicalArray(StringBuilder rCode, String name, boolean[] arr, boolean useEquals) {
String[] stringArray = new String[arr.length];
for (int i = 0; i < arr.length; i++) {
stringArray[i] = String.valueOf(arr[i]).toUpperCase();
}
addArray(rCode, name, stringArray, useEquals, false);
}

public static <T> void addArray(StringBuffer rCode, String name, T[] array, boolean useEquals, boolean isString) {
public static <T> void addArray(StringBuilder rCode, String name, T[] array, boolean useEquals, boolean isString) {
if (!name.equals("")) {
if (useEquals) {
rCode.append(name).append("=");
Expand All @@ -98,14 +98,14 @@ public static <T> void addArray(StringBuffer rCode, String name, T[] array, bool
}
}

public static void addJavaObject(StringBuffer rCode, Object o, boolean useEquals) throws IllegalAccessException {
public static void addJavaObject(StringBuilder rCode, Object o, boolean useEquals) throws IllegalAccessException {
rCode.append(((JavaObject) o).produceRCode(useEquals));
if (!useEquals) {
rCode.append("\n");
}
}

public static void addDoubleMatrix(StringBuffer rCode, String name, double[][] matrix, boolean useEquals) {
public static void addDoubleMatrix(StringBuilder rCode, String name, double[][] matrix, boolean useEquals) {
int dim2 = matrix[0].length;
int counter = 0;
if (!name.equals("")) {
Expand All @@ -131,31 +131,31 @@ public static void addDoubleMatrix(StringBuffer rCode, String name, double[][] m
}
}

public static void addDouble(StringBuffer rCode, String name, double d, boolean useEquals) {
public static void addDouble(StringBuilder rCode, String name, double d, boolean useEquals) {
addValue(rCode, name, d, useEquals);
}

public static void addInt(StringBuffer rCode, String name, int i, boolean useEquals) {
public static void addInt(StringBuilder rCode, String name, int i, boolean useEquals) {
addValue(rCode, name, i, useEquals);
}

public static void addLong(StringBuffer rCode, String name, long l, boolean useEquals) {
public static void addLong(StringBuilder rCode, String name, long l, boolean useEquals) {
addValue(rCode, name, l, useEquals);
}

public static void addFloat(StringBuffer rCode, String name, float f, boolean useEquals) {
public static void addFloat(StringBuilder rCode, String name, float f, boolean useEquals) {
addValue(rCode, name, String.valueOf(f).toUpperCase(), useEquals);
}

public static void addShort(StringBuffer rCode, String name, short s, boolean useEquals) {
public static void addShort(StringBuilder rCode, String name, short s, boolean useEquals) {
addValue(rCode, name, s, useEquals);
}

public static void addBoolean(StringBuffer rCode, String name, boolean b, boolean useEquals) {
public static void addBoolean(StringBuilder rCode, String name, boolean b, boolean useEquals) {
addValue(rCode, name, String.valueOf(b).toUpperCase(), useEquals);
}

public static void addString(StringBuffer rCode, String name, String value, boolean useEquals) {
public static void addString(StringBuilder rCode, String name, String value, boolean useEquals) {
if (!name.equals("")) {
if (useEquals) {
rCode.append(name).append("=");
Expand All @@ -173,7 +173,7 @@ public static void addString(StringBuffer rCode, String name, String value, bool
}
}

private static void addValue(StringBuffer rCode, String name, Object value, boolean useEquals) {
private static void addValue(StringBuilder rCode, String name, Object value, boolean useEquals) {
if (!name.equals("")) {
if (useEquals) {
rCode.append(name).append("=").append(value);
Expand All @@ -189,7 +189,7 @@ private static void addValue(StringBuffer rCode, String name, Object value, bool
}
}

public static void addRespectToType(StringBuffer rCode, String name, Object o, boolean useEquals) {
public static void addRespectToType(StringBuilder rCode, String name, Object o, boolean useEquals) {
if (o instanceof double[]) {
RCodeUtils.addDoubleArray(rCode, name, (double[]) o, useEquals);
} else if (o instanceof int[]) {
Expand Down Expand Up @@ -230,7 +230,7 @@ public static void addRespectToType(StringBuffer rCode, String name, Object o, b

}

public static void addDataFrame(StringBuffer rCode, String name, DataFrame dataFrame) {
public static void addDataFrame(StringBuilder rCode, String name, DataFrame dataFrame) {
try {
File file = File.createTempFile("dataFrame", ".csv");
CSVFileWriter csvFileWriter = CSVFileWriter.create(file.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void errorHandlerTest() {
@Test
public void timeoutTest() {
System.out.println("TIMEOUT TEST");
System.out.println("*** This must throw an exception:");
RCaller rcaller = RCaller.create(RCallerOptions.create(FailurePolicy.CONTINUE, 100)); //don't retry
RCode code = RCode.create();

Expand Down

0 comments on commit cf8e0ab

Please sign in to comment.