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

io.yawp.repository.scanner.FeatureTree Maven / Gradle / Ivy

There is a newer version: 2.08alpha
Show newest version
package io.yawp.repository.scanner;

import io.yawp.repository.Feature;

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

public class FeatureTree {

    private Class stopclazz;

    private Set> nodes = new HashSet<>();

    private Set> leaves = new HashSet<>();

    public FeatureTree(Class stopclazz) {
        this.stopclazz = stopclazz;
    }

    public void add(Class clazz) {
        if (!nodes.contains(clazz)) {
            addNode(clazz);
            addLeaf(clazz);
        }
        addHierarchyNodes(clazz);
    }

    private void addHierarchyNodes(Class clazz) {
        Class superclazz = (Class) clazz.getSuperclass();

        if (superclazz == null || superclazz.equals(stopclazz)) {
            return;
        }

        if (nodes.contains(superclazz)) {
            leaves.remove(superclazz);
            return;
        }

        addNode(superclazz);
    }

    private void addLeaf(Class clazz) {
        leaves.add(clazz);
    }

    private void addNode(Class clazz) {
        nodes.add(clazz);
    }

    public Set> getLeaves() {
        return leaves;
    }

    public int size() {
        return nodes.size();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy