private void parseConfig()

in src/main/java/org/apache/datasketches/server/SketchServerConfig.java [86:122]


  private void parseConfig(final JsonElement config) throws IOException {
    final Gson gson = new Gson();

    sketchList = new ArrayList<>();

    if (config.isJsonArray()) {
      // must be a list of fully-described sketches
      sketchList.addAll(Arrays.asList(gson.fromJson(config.getAsJsonArray(), SketchInfo[].class)));
    } else if (config.isJsonObject()) {
      final JsonObject confEntry = config.getAsJsonObject();
      for (final String name : confEntry.keySet()) {
        if (name.equalsIgnoreCase(CONFIG_PORT_FIELD)) {
          // port the server should use
          port = confEntry.get(name).getAsInt();
        }
        else if (name.toLowerCase().startsWith(CONFIG_SKETCHES_PREFIX)) {
          // sketches* is an array of fully qualified sketches
          sketchList.addAll(Arrays.asList(gson.fromJson(confEntry.get(name).getAsJsonArray(), SketchInfo[].class)));
        } else if (name.toLowerCase().startsWith(CONFIG_SET_PREFIX)) {
          // set* has a common name and type with an array of name names
          final JsonObject sketchSetInfo = confEntry.get(name).getAsJsonObject();
          final int k = sketchSetInfo.get(CONFIG_K_FIELD).getAsInt();
          final String family = sketchSetInfo.get(CONFIG_FAMILY_FIELD).getAsString();
          String type = null;
          if (isDistinctCounting(BaseSketchesQueryHandler.familyFromString(family))) {
            type = sketchSetInfo.get(CONFIG_TYPE_FIELD).getAsString();
          }
          final String[] nameList = gson.fromJson(sketchSetInfo.get(CONFIG_SET_NAMES_FIELD).getAsJsonArray(), String[].class);

          for (final String n : nameList)
            sketchList.add(new SketchInfo(n, k, family, type));
        }
      }
    } else {
      throw new IOException("Expected JsonArray or JsonObject but none found");
    }
  }