Package com.github.jsonj

Examples of com.github.jsonj.JsonArray


     * @return a double[][] 2d array of doubles
     */
    public static double[][] fromJsonJLineString(JsonArray lineString) {
        double[][] result = new double[lineString.size()][lineString.get(0).asArray().size()];
        for(int i =0; i<lineString.size();i++) {
            JsonArray subArray = lineString.get(i).asArray();
            for(int j =0; j<subArray.size();j++) {
                result[i][j] = subArray.get(j).asPrimitive().asDouble();
            }
        }
        return result;
    }
View Full Code Here


        return toJsonJPolygon(new double [][][] {polygon});
    }


    public static JsonArray toJsonJPolygon(double[][][] polygon) {
        JsonArray result = array();
        for (double[][] element : polygon) {
            result.add(toJsonJLineString(element));
        }
        return result;
    }
View Full Code Here

        }
        return result;
    }

    public static JsonArray toJsonJMultiPolygon(double[][][][] multiPolygon) {
        JsonArray result = array();
        for (double[][][] element : multiPolygon) {
            result.add(toJsonJPolygon(element));
        }
        return result;
    }
View Full Code Here

     * Takes a two dimensional linestring and creates a three dimensional polygon from it. Also closes the polygon if needed.
     * @param lineString 2d array of doubles
     * @return JsonArray with the 3d polygon
     */
    public static JsonArray lineStringToPolygon(double[][] lineString) {
        JsonArray jsonJLineString = toJsonJLineString(lineString);
        if (lineString[0][0] != lineString[lineString.length - 1][0] || lineString[0][1] != lineString[lineString.length - 1][1]) {
            // add last coordinate to close the polygon
            jsonJLineString.add(array(lineString[0][0], lineString[0][1]));
        }
        JsonArray result = array();
        result.add(jsonJLineString);
        return result;
    }
View Full Code Here

        stack.clear();
    }

    public boolean startArray() {
        isObject = false;
        stack.add(new JsonArray());
        return true;
    }
View Full Code Here

     * @param values one or more {@link String} values
     *            values that go in the array
     * @return the builder
     */
    public JsonBuilder putArray(final String key, final String... values) {
        JsonArray jjArray = new JsonArray();
        for (String string : values) {
            jjArray.add(primitive(string));
        }
        object.put(key, jjArray);
        return this;
    }
View Full Code Here

     * @param values values
     *            values that go in the array
     * @return the builder
     */
    public JsonBuilder putArray(final String key, final Number... values) {
        JsonArray jjArray = new JsonArray();
        for (Number number : values) {
            jjArray.add(primitive(number));
        }
        object.put(key, jjArray);
        return this;
    }
View Full Code Here

    /**
     * @return an empty JsonArray
     */
    public static JsonArray array() {
        return new JsonArray();
    }
View Full Code Here

    /**
     * @param elements one or more json elements
     * @return json array with all the elements added
     */
    public static JsonArray array(final JsonElement... elements) {
        JsonArray jjArray = new JsonArray();
        for (JsonElement jjElement : elements) {
            if(jjElement == null) {
                jjArray.add(nullValue());
            } else {
                jjArray.add(jjElement);
            }
        }
        return jjArray;
    }
View Full Code Here

     *
     * @param c an existing collection. If the elements are JsonElements, they will be added. Otherwise, primitive will be called on them.
     * @return json array with the collection elements in it
     */
    public static JsonArray array(Iterable<?> c) {
        JsonArray jjArray = new JsonArray();
        if(c instanceof JsonElement) {
            jjArray.add((JsonArray)c);
        } else {
            for (Object o : c) {
                if (o instanceof JsonElement) {
                    jjArray.add((JsonElement) o);
                } else {
                    jjArray.add(primitive(o));
                }
            }
        }
        return jjArray;
    }
View Full Code Here

TOP

Related Classes of com.github.jsonj.JsonArray

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.