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

dev.harrel.jsonschema.AnnotationTree Maven / Gradle / Ivy

package dev.harrel.jsonschema;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

final class AnnotationTree {
    private final Map lookupMap = new HashMap<>();

    AnnotationTree() {
        lookupMap.put(null, new Node());
    }

    List getAllAnnotations() {
        return lookupMap.get(null).toList();
    }

    Node getNode(String location) {
        return lookupMap.get(location);
    }

    Node createIfAbsent(String parentLocation, String location) {
        return lookupMap.computeIfAbsent(location, key -> {
            Node node = new Node();
            lookupMap.get(parentLocation).nodes.add(node);
            return node;
        });
    }

    static class Node {
        final List nodes = new ArrayList<>();
        final List annotations = new ArrayList<>();

        List toList() {
            List result = new ArrayList<>();
            for (Node node : nodes) {
                result.addAll(node.toList());
            }
            result.addAll(annotations);
            return result;
        }
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy