/**
 * 
 */
package de.dhbwstuttgart.bytecode.genericsGeneratorTypes;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * The simplify results of a source file (package)
 * 
 * @author fayez
 *
 */
public class GenericGenratorResultForSourceFile {
	private String pkgName;
	private final List<GenericsGeneratorResultForClass> genericGeneratorResultForAllClasses = new ArrayList<>();

	/**
	 * @param pkgName
	 */
	public GenericGenratorResultForSourceFile(String pkgName) {
		this.pkgName = pkgName;
	}

	public List<GenericsGeneratorResultForClass> getGenericGeneratorResultForAllClasses() {
		return genericGeneratorResultForAllClasses;
	}

	/**
	 * Appends the simplify results of a class to simplifyResForSF
	 * 
	 * @param sResClass simplify results of a class to added
	 */
	public void addGenericGeneratorResultClass(GenericsGeneratorResultForClass sResClass) {
		genericGeneratorResultForAllClasses.add(sResClass);
	}

	public GenericsGeneratorResultForClass getSimplifyResultsByName(String pkgName, String name) {

		if (this.pkgName.equals(pkgName)) {
			return genericGeneratorResultForAllClasses.stream()
					.filter(sr -> sr.getClassName().equals(name))
					.findAny()
					.orElseThrow(() -> new NoSuchElementException(
							"Simplify results for the class " + pkgName + "." + name + " are not found"));
		}
		throw new NoSuchElementException("Simplify results for the class " + pkgName + "." + name + " are not found");
	}
}
