package ch.ntb.inf.deep.config;

import ch.ntb.inf.deep.strings.HString;

public class TargetConfiguration {
		
	Module targetConfig;
	HString name;
	TargetConfiguration next;
	
	public TargetConfiguration(HString name){
		this.name = name;
	}
	
	public void setModule(Module mod) {
		if (targetConfig == null) {
			targetConfig = mod;
		}
		int modHash = mod.name.hashCode();
		Module current = targetConfig;
		Module prev = null;
		while (current != null) {
			if (current.name.hashCode() == modHash) {
				if (current.name.equals(mod.name)) {
					//TODO warn the User
					mod.next = current.next;
					if(prev != null){
						prev.next = mod;
					}else{
						targetConfig = mod;
					}
					return;
				}
			}
			prev = current;
			current = current.next;
		}
		//if no match prev shows the tail of the list
		prev.next = mod;
	}

	public Module getModules(){
		return targetConfig;
	}
	
	public void print(int indentLevel){
		for(int i = indentLevel; i > 0; i--){
			System.out.print("  ");
		}
		System.out.println("TargetConfiguration " + name.toString() + " {");
		Module current = targetConfig;
		while(current != null){
			current.println(indentLevel + 1);
			current = current.next;
		}
		for(int i = indentLevel; i > 0; i--){
			System.out.print("  ");
		}
		System.out.println("}");
	}
}

@@ -925,32 +925,363 @@
 Config;%0D%0A%09%7D%0D%0A%09%0D%0A
+%09public Module getModuleByName(HString moduleName)%7B%0D%0A%09%09int modHash = moduleName.hashCode();%0D%0A%09%09Module current = targetConfig;%0D%0A%09%09while(current != null)%7B%0D%0A%09%09%09if(current.name.hashCode() == modHash)%7B%0D%0A%09%09%09%09if(current.name.equals(moduleName))%7B%0D%0A%09%09%09%09%09return current;%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%09current = current.next;%0D%0A%09%09%7D%0D%0A%09%09return null;%0D%0A%09%7D%0D%0A%09%0D%0A
 %09public void pri

add method getModuleByName(HString name)