*
* @return XLObject.
*/
public XLoper createFrom(Object obj) {
if (obj instanceof String) {
return new XLString((String) obj);
} else if (obj instanceof Boolean) {
return new XLBool(((Boolean) obj).booleanValue());
} else if (obj instanceof Integer) {
return new XLNum(((Integer) obj).intValue());
} else if (obj instanceof Long) {
return new XLNum(((Long) obj).longValue());
} else if (obj instanceof Float) {
return new XLNum(((Float) obj).floatValue());
} else if (obj instanceof Double) {
return new XLNum(((Double) obj).doubleValue());
} else if (obj instanceof String[]) {
String[] arr = (String[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = new XLString(arr[i]);
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof String[][]) {
String[][] arr = (String[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof double[]) {
double[] arr = (double[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = new XLNum(arr[i]);
}
return new XLArray(array, array.length, 1);
} else if (obj instanceof double[][]) {
double[][] arr = (double[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof Double[]) {
Double[] arr = (Double[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = arr[i] == null ? (XLoper) XLNil.NIL : new XLNum(
arr[i].doubleValue());
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof Double[][]) {
Double[][] arr = (Double[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof int[]) {
int[] arr = (int[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = new XLInt(arr[i]);
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof int[][]) {
int[][] arr = (int[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof Integer[]) {
Integer[] arr = (Integer[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = arr[i] == null ? (XLoper) XLNil.NIL : new XLInt(
arr[i].intValue());
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof Integer[][]) {
Integer[][] arr = (Integer[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof boolean[]) {
boolean[] arr = (boolean[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = new XLBool(arr[i]);
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof boolean[][]) {
boolean[][] arr = (boolean[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof Boolean[]) {
Boolean[] arr = (Boolean[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = arr[i] == null ? (XLoper) XLNil.NIL : new XLBool(
arr[i].booleanValue());
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof Boolean[][]) {
Boolean[][] arr = (Boolean[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, arr[i][j]);
}
}
return array;
} else if (obj instanceof Object[][]) {
Object[][] arr = (Object[][]) obj;
if (arr.length == 0 || arr[0] == null)
return XLError.NA;
XLArray array = new XLArray(arr.length, arr[0].length);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length && j < arr[i].length; j++) {
array.set(i, j, createFrom(arr[i][j]));
}
}
return array;
} else if (obj instanceof Object[]) {
Object[] arr = (Object[]) obj;
XLoper[] array = new XLoper[arr.length];
for (int i = 0; i < arr.length; i++) {
array[i] = createFrom(arr[i]);
}
return new XLArray(array, arr.length, 1);
} else if (obj instanceof XLoper) {
return (XLoper) obj;
} else if (obj != null) {
return new XLString(registry.put(obj));
} else {
return XLNil.NIL;
}
}