Example usage for com.google.gson JsonArray size

List of usage examples for com.google.gson JsonArray size

Introduction

In this page you can find the example usage for com.google.gson JsonArray size.

Prototype

public int size() 

Source Link

Document

Returns the number of elements in the array.

Usage

From source file:com.google.dart.server.generated.types.TypeHierarchyItem.java

License:Open Source License

public static List<TypeHierarchyItem> fromJsonArray(JsonArray jsonArray) {
    if (jsonArray == null) {
        return EMPTY_LIST;
    }//  ww w .  j ava  2s .  c  om
    ArrayList<TypeHierarchyItem> list = new ArrayList<TypeHierarchyItem>(jsonArray.size());
    Iterator<JsonElement> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
        list.add(fromJson(iterator.next().getAsJsonObject()));
    }
    return list;
}

From source file:com.google.dart.server.internal.remote.processor.JsonProcessor.java

License:Open Source License

/**
 * Given some {@link JsonArray} and of {@code int} primitives, return the {@code int[]}.
 * /* w w  w  . ja  v  a2  s  . c  o  m*/
 * @param intJsonArray some {@link JsonArray} of {@code int}s
 * @return the {@code int[]}
 */
protected int[] constructIntArray(JsonArray intJsonArray) {
    if (intJsonArray == null) {
        return new int[] {};
    }
    int i = 0;
    int[] ints = new int[intJsonArray.size()];
    Iterator<JsonElement> iterator = intJsonArray.iterator();
    while (iterator.hasNext()) {
        ints[i] = iterator.next().getAsInt();
        i++;
    }
    return ints;
}

From source file:com.google.dart.server.utilities.general.JsonUtilities.java

License:Open Source License

public static Boolean[] decodeBooleanArray(JsonArray jsonArray) {
    if (jsonArray == null) {
        return new Boolean[0];
    }//  w  ww. j ava2s . co m
    int i = 0;
    Boolean[] booleanArray = new Boolean[jsonArray.size()];
    Iterator<JsonElement> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
        booleanArray[i] = iterator.next().getAsBoolean();
        i++;
    }
    return booleanArray;
}

From source file:com.google.dart.server.utilities.general.JsonUtilities.java

License:Open Source License

public static int[] decodeIntArray(JsonArray jsonArray) {
    if (jsonArray == null) {
        return new int[0];
    }//  ww w. ja v  a2 s. c o m
    int i = 0;
    int[] intArray = new int[jsonArray.size()];
    Iterator<JsonElement> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
        intArray[i] = iterator.next().getAsInt();
        i++;
    }
    return intArray;
}

From source file:com.google.dart.server.utilities.general.JsonUtilities.java

License:Open Source License

public static Integer[] decodeIntegerArray(JsonArray jsonArray) {
    if (jsonArray == null) {
        return new Integer[0];
    }//  w  ww  .java 2s . co  m
    int i = 0;
    Integer[] intArray = new Integer[jsonArray.size()];
    Iterator<JsonElement> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
        intArray[i] = iterator.next().getAsInt();
        i++;
    }
    return intArray;
}

From source file:com.google.dart.server.utilities.general.JsonUtilities.java

License:Open Source License

public static List<String> decodeStringList(JsonArray jsonArray) {
    if (jsonArray == null) {
        return StringUtilities.EMPTY_LIST;
    }/*from  w  w w. j  av  a 2  s .  co m*/
    List<String> stringList = new ArrayList<String>(jsonArray.size());
    Iterator<JsonElement> iterator = jsonArray.iterator();
    while (iterator.hasNext()) {
        stringList.add(iterator.next().getAsString());
    }
    return stringList;
}

From source file:com.google.debugging.sourcemap.SourceMapConsumerV3.java

License:Apache License

/**
 * @param sourceMapRoot/* w w w .ja va 2s . c  om*/
 * @throws SourceMapParseException
 */
private void parseMetaMap(JsonObject sourceMapRoot, SourceMapSupplier sectionSupplier)
        throws SourceMapParseException {
    if (sectionSupplier == null) {
        sectionSupplier = new DefaultSourceMapSupplier();
    }

    try {
        // Check basic assertions about the format.
        int version = sourceMapRoot.get("version").getAsInt();
        if (version != 3) {
            throw new SourceMapParseException("Unknown version: " + version);
        }

        String file = sourceMapRoot.get("file").getAsString();
        if (file.isEmpty()) {
            throw new SourceMapParseException("File entry is missing or empty");
        }

        if (sourceMapRoot.has("lineCount") || sourceMapRoot.has("mappings") || sourceMapRoot.has("sources")
                || sourceMapRoot.has("names")) {
            throw new SourceMapParseException("Invalid map format");
        }

        SourceMapGeneratorV3 generator = new SourceMapGeneratorV3();
        JsonArray sections = sourceMapRoot.get("sections").getAsJsonArray();
        for (int i = 0, count = sections.size(); i < count; i++) {
            JsonObject section = sections.get(i).getAsJsonObject();
            if (section.has("map") && section.has("url")) {
                throw new SourceMapParseException(
                        "Invalid map format: section may not have both 'map' and 'url'");
            }
            JsonObject offset = section.get("offset").getAsJsonObject();
            int line = offset.get("line").getAsInt();
            int column = offset.get("column").getAsInt();
            String mapSectionContents;
            if (section.has("url")) {
                String url = section.get("url").getAsString();
                mapSectionContents = sectionSupplier.getSourceMap(url);
                if (mapSectionContents == null) {
                    throw new SourceMapParseException("Unable to retrieve: " + url);
                }
            } else if (section.has("map")) {
                mapSectionContents = section.get("map").toString();
            } else {
                throw new SourceMapParseException(
                        "Invalid map format: section must have either 'map' or 'url'");
            }
            generator.mergeMapSection(line, column, mapSectionContents);
        }

        StringBuilder sb = new StringBuilder();
        try {
            generator.appendTo(sb, file);
        } catch (IOException e) {
            // Can't happen.
            throw new RuntimeException(e);
        }

        parse(sb.toString());
    } catch (IOException ex) {
        throw new SourceMapParseException("IO exception: " + ex);
    } catch (JsonParseException ex) {
        throw new SourceMapParseException("JSON parse exception: " + ex);
    }
}

From source file:com.google.debugging.sourcemap.SourceMapConsumerV3.java

License:Apache License

private String[] getJavaStringArray(JsonArray array) throws JsonParseException {
    int len = array.size();
    String[] result = new String[len];
    for (int i = 0; i < len; i++) {
        result[i] = array.get(i).getAsString();
    }/*from  w ww  .  j  ava2 s  .  c  o  m*/
    return result;
}

From source file:com.google.debugging.sourcemap.SourceMapObject.java

License:Apache License

private static String[] getJavaStringArray(JsonElement element) throws JsonParseException {
    if (element == null) {
        return null;
    }/*from   ww w . j a  v a2 s  .c o m*/
    JsonArray array = element.getAsJsonArray();
    int len = array.size();
    String[] result = new String[len];
    for (int i = 0; i < len; i++) {
        result[i] = array.get(i).getAsString();
    }
    return result;
}

From source file:com.google.debugging.sourcemap.SourceMapObjectParser.java

License:Apache License

private static String[] getJavaStringArray(JsonElement element) {
    if (element == null) {
        return null;
    }/*  www  .  j  a  v  a2  s . c o  m*/
    JsonArray array = element.getAsJsonArray();
    int len = array.size();
    String[] result = new String[len];
    for (int i = 0; i < len; i++) {
        result[i] = array.get(i).getAsString();
    }
    return result;
}