All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dimajix.shaded.everit.schema.loader.SubschemaRegistry Maven / Gradle / Ivy

There is a newer version: 1.2.0-synapse3.3-spark3.3-hadoop3.3
Show newest version
package com.dimajix.shaded.everit.schema.loader;

import java.util.HashMap;
import java.util.Map;

class SubschemaRegistry {

    final Map storage = new HashMap<>();


    SubschemaRegistry(JsonValue rootJson) {
        collectObjectsWithId(rootJson);
    }

    void collectObjectsWithId(JsonValue val) {
        String idKeyword = val.ls.specVersion().idKeyword();
        if (val instanceof JsonObject) {
            JsonObject obj = (JsonObject) val;
            if (obj.containsKey(idKeyword)
                && obj.require(idKeyword).typeOfValue() == String.class) {
                storage.put(obj.require(idKeyword).requireString(), obj);
            }
            for (String key : obj.keySet()) {
                collectObjectsWithId(obj.require(key));
            }
        } else if (val instanceof JsonArray) {
            JsonArray arr = (JsonArray) val;
            for (int i = 0; i < arr.length(); ++i) {
                collectObjectsWithId(arr.at(i));
            }
        }
    }

    JsonObject getById(String id) {
        return storage.get(id);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy