Package org.mozilla.javascript

Examples of org.mozilla.javascript.NativeArray


import org.mozilla.javascript.NativeArray;

public class Bug492525Test {
  @Test
  public void getAllIdsShouldIncludeArrayIndices() {
    NativeArray array = new NativeArray(new String[]{"a", "b"});
    Object[] expectedIds = new Object[] {0, 1, "length"};
    Object[] actualIds = array.getAllIds();
    assertArrayEquals(expectedIds, actualIds);
  }
View Full Code Here


        TreeMap<String, FileData> map = new TreeMap<String, FileData>();
        try {
            NativeObject json = (NativeObject) parser.parseValue(data);
            for (Object scriptURI : json.keySet()) {
                NativeObject scriptData = (NativeObject) json.get(scriptURI);
                NativeArray lineCoverageArray = (NativeArray) scriptData.get("lineData");
                NativeObject branchJSONArray = (NativeObject) scriptData.get("branchData");
                List<Integer> countData = new ArrayList<Integer>(lineCoverageArray.size());
                for (int i = 0; i < lineCoverageArray.size(); i++)
                    countData.add((Integer) lineCoverageArray.get(i));
   
                // Function Coverage (HA-CA)
                NativeArray functionCoverageArray = (NativeArray) scriptData.get("functionData");
                List<Integer> funcData = new ArrayList<Integer>();
                if (functionCoverageArray != null) {
                    for (int i = 0; i < functionCoverageArray.size(); i++)
                        funcData.add((Integer) functionCoverageArray.get(i));
                }

                SortedMap<Integer, List<BranchData>> branchLineMap = new TreeMap<Integer, List<BranchData>>();
                if (branchJSONArray != null) {
                    readBranchLines(branchJSONArray, branchLineMap);
View Full Code Here

                bounds = new Bounds(config);
            } else {
                bounds = new Bounds(config.getParentScope(), config);
            }
        } else if (arg instanceof NativeArray) {
            NativeArray array = (NativeArray) arg;
            if (inNewExpr) {
                bounds = new Bounds(array);
            } else {
                bounds = new Bounds(array.getParentScope(), array);
            }
        } else {
            throw ScriptRuntime.constructError("Error", "Bounds constructor takes an object or array.");
        }
        return bounds;
View Full Code Here

        NativeObject config = null;
        if (configObj instanceof NativeObject) {
            getRequiredMember(configObj, "coordinates", NativeArray.class, "Array");
            config = (NativeObject) configObj;
        } else if (configObj instanceof NativeArray) {
            NativeArray array = (NativeArray) configObj;
            config = (NativeObject) context.newObject(scope);
            config.put("coordinates", config, array);
        } else {
            throw ScriptRuntime.constructError("Error",
                    "Geometry config must be an array or an object with a coordinates member");
View Full Code Here

        Scriptable scope = getParentScope();
        Context cx = getCurrentContext();
        Object[] elements = new Object[] {
                coord.x, coord.y
        };
        NativeArray array = (NativeArray) cx.newArray(scope, elements);
        double z = coord.z;
        if (!Double.isNaN(z)) {
            array.put(2, array, z);
        }
        return array;
    }
View Full Code Here

     */
    protected NativeArray coordsToArray(Coordinate[] coords) {
        Scriptable scope = getParentScope();
        Context cx = getCurrentContext();
        int length = coords.length;
        NativeArray array = (NativeArray) cx.newArray(scope, length);
        for (int i=0; i<length; ++i) {
            array.put(i, array, coordToArray(coords[i]));
        }
        return array;
    }
View Full Code Here

    }
   
    @JSGetter
    public NativeArray getEndPoints() {
        Context cx = getCurrentContext();
        NativeArray components = getComponents();
        int size = components.size();
        Scriptable scope = getParentScope();
        NativeArray array = (NativeArray) cx.newArray(scope, 2*size);
        for (int i=0; i<size; ++i) {
            com.vividsolutions.jts.geom.LineString geom = (com.vividsolutions.jts.geom.LineString) components.get(i);
            LineString line = (LineString) GeometryWrapper.wrap(scope, geom);
            array.put(2*i, array, line.getStartPoint());
            array.put((2*i)+1, array, line.getEndPoint());
        }
        return array;
    }
View Full Code Here

    /**
     * Constructor for config object.
     * @param prepConfig
     */
    public Point(NativeObject config) {
        NativeArray array = (NativeArray) config.get("coordinates", config);
        Coordinate coord = arrayToCoord(array);
        setGeometry(factory.createPoint(coord));
    }
View Full Code Here

    @JSConstructor
    public static Object constructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
        if (args.length != 1) {
            throw ScriptRuntime.constructError("Error", "MultiPoint constructor takes a single argument");
        }
        NativeArray array = getCoordinatesArray(args[0]);
        MultiPoint collection = null;
        if (inNewExpr) {
            collection = new MultiPoint(array);
        } else {
            collection = new MultiPoint(array.getParentScope(), array);
        }
        return collection;
    }
View Full Code Here

     * @param context
     * @param scope
     * @param array
     */
    public Polygon(NativeObject config) {
        NativeArray array = (NativeArray) config.get("coordinates", config);
        LinearRing shell = factory.createLinearRing(arrayToCoords((NativeArray) array.get(0)));
        int numHoles = array.size() - 1;
        LinearRing[] holes = new LinearRing[numHoles];
        for (int i=0; i<numHoles; ++i) {
            holes[i] = factory.createLinearRing(arrayToCoords((NativeArray) array.get(i+1)));
        }
        setGeometry(factory.createPolygon(shell, holes));
    }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.NativeArray

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.