information-system-model-do.../src/main/java/org/gcube/informationsystem/utils/documentation/knowledge/Tree.java

54 lines
1.2 KiB
Java
Raw Normal View History

2023-01-22 19:44:32 +01:00
package org.gcube.informationsystem.utils.documentation.knowledge;
import java.util.HashMap;
2023-01-23 16:21:01 +01:00
import java.util.Set;
import org.gcube.informationsystem.types.reference.Type;
2023-01-22 19:44:32 +01:00
/**
2023-01-23 16:21:01 +01:00
* @author Luca Frosini (ISTI - CNR)
2023-01-22 19:44:32 +01:00
*/
2023-01-23 16:21:01 +01:00
public class Tree {
private Node root;
private boolean allowMultipleInheritance;
private HashMap<String, Node> locate = new HashMap<String, Node>();
public Tree(Type head) {
this.root = new Node(head);
this.locate.put(head.getName(), root);
this.allowMultipleInheritance = false;
}
public void setAllowMultipleInheritance(boolean allowMultipleInheritance) {
this.allowMultipleInheritance = allowMultipleInheritance;
}
public void addNode(Type t) {
Set<String> superClasses = t.getSuperClasses();
for(String superClass : superClasses) {
Node parent = locate.get(superClass);
if(parent==null) {
throw new RuntimeException("I can find parent Node for " + t.getName() + ". Missing parent is " + superClass);
}
Node node = new Node(t);
parent.addChild(node);
locate.put(t.getName(), node);
if(!allowMultipleInheritance) {
return;
2023-01-22 19:44:32 +01:00
}
}
}
2023-01-23 16:21:01 +01:00
public Node getRoot() {
return root;
2023-01-22 19:44:32 +01:00
}
@Override
public String toString() {
2023-01-23 16:21:01 +01:00
return root.toString();
2023-01-22 19:44:32 +01:00
}
2023-01-23 16:21:01 +01:00
}