package com.hammurapi.reasoning.impl;

import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;

import com.hammurapi.flow.Flow;

/**
 * Optimizes flow by setting inline flag to true for nodes and 
 * transitions which form a chain and therefore there is no reason
 * to spawn multiple task for execution of each of them.
 * @author Pavel Vlasov
 *
 */
public class IniliningOptimizer implements RuleSetFlowOptimizer {

	/*
	 * Algorithm:
	 * 1. Iterate over nodes.
	 * 2. If the node has one outbound transition to another node, 
	 *    then mark the transition and the target node as inline..
	 */
	
	@Override
	public void optimize(Flow ruleSetFlow) {		
		boolean optimized;
		Z: do {
			optimized = false;
			TreeIterator<EObject> rcit = ruleSetFlow.eAllContents();
			while (rcit.hasNext()) {
				EObject next = rcit.next();
				
				throw new UnsupportedOperationException();
			}						
		} while (optimized);		
	}
	
	/**
	 * This optimization shall be executed after transition sharing optimization.
	 */
	@Override
	public int getOrder() {
		return 20;
	}

}
