Package org.boris.xlloop.xloper

Examples of org.boris.xlloop.xloper.XLArray


            o.put("int", ((XLInt) x).w);
            break;
        case XLoper.xlTypeMissing:
            break;
        case XLoper.xlTypeMulti:
            XLArray a = (XLArray) x;
            o.put("rows", a.rows);
            o.put("cols", a.columns);
            JSONArray ja = new JSONArray();
            for (int i = 0; i < a.length; i++) {
                ja.put(encode(a.array[i]));
View Full Code Here


            XLoper[] a = new XLoper[len];
            JSONArray ja = jo.getJSONArray("array");
            for (int i = 0; i < len; i++) {
                a[i] = decode(ja.getJSONObject(i));
            }
            return new XLArray(a, rows, cols);
        case XLoper.xlTypeNil:
            return XLNil.NIL;
        case XLoper.xlTypeNum:
            return new XLNum(jo.getDouble("num"));
        case XLoper.xlTypeStr:
View Full Code Here

        for (int i = 0; i < size; i += 2) {
            String key = (String) iter.next();
            data[i] = new XLString(key);
            data[i + 1] = (XLoper) map.get(key);
        }
        return new XLArray(data, size >> 1, 2);
    }
View Full Code Here

            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 {
View Full Code Here

            return ((XLString) x).str;
        return null;
    }

    public XLArray toXLoper() {
        return new XLArray(toArray(), list.size(), 1);
    }
View Full Code Here

    public XLoper get(int row, int column) {
        return values.get(new ArrayRef(row, column));
    }

    public XLoper toXLoper() {
        XLArray a = new XLArray(maxRow - minRow + 1, maxCol - minCol + 1);
        for (Iterator i = values.keySet().iterator(); i.hasNext();) {
            ArrayRef r = (ArrayRef) i.next();
            a.set(r.row - minRow, r.column - minCol, (XLoper) values.get(r));
        }
        return a;
    }
View Full Code Here

    public static Class[] createArgHints(XLoper[] args) {
        Class[] hints = new Class[args.length];
        for (int i = 0; i < hints.length; i++) {
            XLoper v = args[i];
            if (v instanceof XLArray) {
                XLArray c = (XLArray) v;
                if (c.columns > 1) {
                    hints[i] = Object[][].class;
                } else {
                    hints[i] = Object[].class;
                }
View Full Code Here

{
    private static String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    public XLoper execute(IFunctionContext context, String name, XLoper[] args) throws RequestException {
        if (name.equals("RandTest")) {
            XLArray x = new XLArray((int) (Math.random() * 10 + 2), 1);
            for (int i = 0; i < x.length; i++) {
                x.array[i] = makeRandom();
            }
            return x;
        } else if (name.equals("ArrayTest")) {
            // Threads.sleep(15000);
            XLArray x = new XLArray(15, 10);
            for (int i = 0; i < 15; i++) {
                int len = (int) (Math.random() * 10) + 1;
                for (int j = 0; j < len; j++) {
                    x.set(i, j, i * j);
                }
            }
            return x;
        } else if (name.equals("ArgsTest")) {
            return new XLList(args).toXLoper();
View Full Code Here

        case 4:
            return new XLString(makeRandomString(0));
        case 5:
            return new XLString(makeRandomString(30, true));
        case 6:
            return new XLArray(2, 1);
        default:
            return XLMissing.MISSING;
        }
    }
View Full Code Here

        assertEquals(o[1][0], new Double(3.2));
        assertEquals(o[1][1], new Integer(45));
    }

    public void testXLArray() throws Exception {
        XLArray a2 = (XLArray) xlo.createFrom(a, XLArray.class);
        assertEquals(a, a2);
    }
View Full Code Here

TOP

Related Classes of org.boris.xlloop.xloper.XLArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.