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

org.unipop.schema.element.SchemaSet Maven / Gradle / Ivy

package org.unipop.schema.element;

import java.util.HashSet;
import java.util.Set;

public class SchemaSet {

    Set schemas = new HashSet<>();

    public void add(ElementSchema schema){
        this.schemas.add(schema);
    }

    public Set get(Boolean recursive) {
        if(!recursive) return schemas;

        Set result = new HashSet<>();
        addRecursive(result, this.schemas);
        return result;
    }

    private void addRecursive(Set result, Set schemas) {
        schemas.forEach(schema -> {
            if(result.contains(schema)) return;
            result.add(schema);
            Set childSchemas = schema.getChildSchemas();
            addRecursive(result, childSchemas);
        });
    }

    public  Set get(Class c, Boolean recursive){
        Set result = new HashSet<>();
        this.get(recursive).forEach(schema -> {
            if(c.isAssignableFrom(schema.getClass())) result.add((T)schema);
        });
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy