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

gr.uom.java.xmi.diff.CallTree Maven / Gradle / Ivy

package gr.uom.java.xmi.diff;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import gr.uom.java.xmi.UMLOperation;

public class CallTree {
	private CallTreeNode root;
	
	public CallTree(CallTreeNode root) {
		this.root = root;
	}
	
	public List getNodesInBreadthFirstOrder() {
		List nodes = new ArrayList();
		List queue = new LinkedList();
		nodes.add(root);
		queue.add(root);
		while(!queue.isEmpty()) {
			CallTreeNode node = queue.remove(0);
			nodes.addAll(node.getChildren());
			queue.addAll(node.getChildren());
		}
		return nodes;
	}
	
	public boolean containsInPathToRootOrSibling(CallTreeNode parent, UMLOperation invokedOperation) {
		CallTreeNode currentParent = parent;
		while(currentParent != null) {
			if(currentParent.getInvokedOperation().equals(invokedOperation)) {
				return true;
			}
			if(currentParent.getOriginalOperation().isRecursive()) {
				for(CallTreeNode sibling : currentParent.getChildren()) {
					if(sibling.getInvokedOperation().equals(invokedOperation)) {
						return true;
					}
				}
			}
			currentParent = currentParent.getParent();
		}
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy