<commit_before>package de.uka.ipd.sdq.beagle.core.pcmconnection;

import de.uka.ipd.sdq.beagle.core.ResourceDemandType;
import de.uka.ipd.sdq.beagle.core.evaluableexpressions.ConstantExpression;
import de.uka.ipd.sdq.beagle.core.evaluableexpressions.EvaluableExpression;

import org.eclipse.emf.common.util.EList;
import org.palladiosimulator.pcm.resourcetype.ProcessingResourceType;
import org.palladiosimulator.pcm.seff.impl.BranchActionImpl;
import org.palladiosimulator.pcm.seff.impl.ExternalCallActionImpl;
import org.palladiosimulator.pcm.seff.impl.InternalActionImpl;
import org.palladiosimulator.pcm.seff.impl.LoopActionImpl;
import org.palladiosimulator.pcm.seff.seff_performance.ParametricResourceDemand;

/**
 * This class contains the logic for converting and annotating EvaluableExpressions.
 * 
 * @author <NAME>
 */
public class PcmRepositoryWriterAnnotatorEvaEx {

	/**
	 * /** The Mappings of InternalAction's {@link ProcessingResourceType} to
	 * {@link ResourceDemandType} from Beagle.
	 */
	private final ResourceTypeMappings typeMappings;

	/**
	 * Constructor.
	 */
	public PcmRepositoryWriterAnnotatorEvaEx() {
		this.typeMappings = new ResourceTypeMappings();
		this.typeMappings.initialise();
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param loopAction The PCM element
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final LoopActionImpl loopAction, final EvaluableExpression evaEx) {
		loopAction.getIterationCount_LoopAction().setSpecification(this.evaExToSpecification(evaEx));
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param branchAction The PCM element
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final BranchActionImpl branchAction, final EvaluableExpression evaEx) {
		// CAN NOT BE DONE YET. THE IMPLEMENTATION OF SEFFBRANCH DOES NOT REFLECT
		// THE STRUCTURE OF A BRANCHACTION, AS A SEFFBRANCH (A MEASURABLESEFFELEMENT)
		// WILL ONLY BE ANNOTATED WITH ONE EXPRESSION, NOT FOR EACH BRACH A NEWLY ONE.
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param internalAction The PCM element
	 * @param type The ResourceDemandType of the InternalAction (
	 *            {@link ResourceDemandType#RESOURCE_TYPE_CPU_NS} and
	 *            {@link ResourceDemandType#RESOURCE_TYPE_HDD_NS} are accepted so far
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final InternalActionImpl internalAction, final ResourceDemandType type,
		final EvaluableExpression evaEx) {
		final EList<ParametricResourceDemand> parametricResourceDemands = internalAction.getResourceDemand_Action();
		for (ParametricResourceDemand parametricResourceDemand : parametricResourceDemands) {
			final ProcessingResourceType processingResourceType =
				parametricResourceDemand.getRequiredResource_ParametricResourceDemand();

			if (this.typeMappings.getBeagleType(processingResourceType) == type) {
				parametricResourceDemand.getSpecification_ParametericResourceDemand()
					.setSpecification(this.evaExToSpecification(evaEx));
			}

		}
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param externalAction The PCM element
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final ExternalCallActionImpl externalAction, final EvaluableExpression evaEx) {
		// MAY BE IMPLEMENTED AS NICE TO HAVE CRITERIA, TOGHETHER WITH THE GENETIC
		// APPROACH
	}

	/**
	 * Supports only Constant EvaluableExpressions right now. Converts EvaluableExpression
	 * into a String-specification of the PCM Stochastic Expression.
	 * 
	 *
	 * @param evaEx constant EvaluableExpression
	 * @return String specification of EvaluableExpression
	 */
	private String evaExToSpecification(final EvaluableExpression evaEx) {
		if (evaEx.getClass() == ConstantExpression.class) {
			return ((ConstantExpression) evaEx).getValue() + "";
		}
		return "";
	}
}<commit_msg>Throwing NullPointerException for null-arguments in annotateEvaEvFor-methods<commit_after>package de.uka.ipd.sdq.beagle.core.pcmconnection;

import de.uka.ipd.sdq.beagle.core.ResourceDemandType;
import de.uka.ipd.sdq.beagle.core.evaluableexpressions.ConstantExpression;
import de.uka.ipd.sdq.beagle.core.evaluableexpressions.EvaluableExpression;

import org.eclipse.emf.common.util.EList;
import org.palladiosimulator.pcm.resourcetype.ProcessingResourceType;
import org.palladiosimulator.pcm.seff.impl.BranchActionImpl;
import org.palladiosimulator.pcm.seff.impl.ExternalCallActionImpl;
import org.palladiosimulator.pcm.seff.impl.InternalActionImpl;
import org.palladiosimulator.pcm.seff.impl.LoopActionImpl;
import org.palladiosimulator.pcm.seff.seff_performance.ParametricResourceDemand;

/**
 * This class contains the logic for converting and annotating EvaluableExpressions.
 * 
 * @author <NAME>
 */
public class PcmRepositoryWriterAnnotatorEvaEx {

	/**
	 * /** The Mappings of InternalAction's {@link ProcessingResourceType} to
	 * {@link ResourceDemandType} from Beagle.
	 */
	private final ResourceTypeMappings typeMappings;

	/**
	 * Constructor.
	 */
	public PcmRepositoryWriterAnnotatorEvaEx() {
		this.typeMappings = new ResourceTypeMappings();
		this.typeMappings.initialise();
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param loopAction The PCM element
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final LoopActionImpl loopAction, final EvaluableExpression evaEx) {
		if (loopAction == null || evaEx == null) {
			throw new NullPointerException("No null arguments in annotateEvaExFor-method allowed!");
		}
		loopAction.getIterationCount_LoopAction().setSpecification(this.evaExToSpecification(evaEx));
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param branchAction The PCM element
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final BranchActionImpl branchAction, final EvaluableExpression evaEx) {
		if (branchAction == null || evaEx == null) {
			throw new NullPointerException("No null arguments in annotateEvaExFor-method allowed!");
		}
		// CAN NOT BE DONE YET. THE IMPLEMENTATION OF SEFFBRANCH DOES NOT REFLECT
		// THE STRUCTURE OF A BRANCHACTION, AS A SEFFBRANCH (A MEASURABLESEFFELEMENT)
		// WILL ONLY BE ANNOTATED WITH ONE EXPRESSION, NOT FOR EACH BRACH A NEWLY ONE.
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param internalAction The PCM element
	 * @param type The ResourceDemandType of the InternalAction (
	 *            {@link ResourceDemandType#RESOURCE_TYPE_CPU_NS} and
	 *            {@link ResourceDemandType#RESOURCE_TYPE_HDD_NS} are accepted so far
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final InternalActionImpl internalAction, final ResourceDemandType type,
		final EvaluableExpression evaEx) {
		if (internalAction == null || evaEx == null) {
			throw new NullPointerException("No null arguments in annotateEvaExFor-method allowed!");
		}
		final EList<ParametricResourceDemand> parametricResourceDemands = internalAction.getResourceDemand_Action();
		for (ParametricResourceDemand parametricResourceDemand : parametricResourceDemands) {
			final ProcessingResourceType processingResourceType =
				parametricResourceDemand.getRequiredResource_ParametricResourceDemand();

			if (this.typeMappings.getBeagleType(processingResourceType) == type) {
				parametricResourceDemand.getSpecification_ParametericResourceDemand()
					.setSpecification(this.evaExToSpecification(evaEx));
			}

		}
	}

	/**
	 * Annotating the EvaluableExpression onto the given PCM element.
	 *
	 * @param externalAction The PCM element
	 * @param evaEx The Expression to annotate
	 */
	public void annotateEvaExFor(final ExternalCallActionImpl externalAction, final EvaluableExpression evaEx) {
		if (externalAction == null || evaEx == null) {
			throw new NullPointerException("No null arguments in annotateEvaExFor-method allowed!");
		}
		// MAY BE IMPLEMENTED AS NICE TO HAVE CRITERIA, TOGHETHER WITH THE GENETIC
		// APPROACH
	}

	/**
	 * Supports only Constant EvaluableExpressions right now. Converts EvaluableExpression
	 * into a String-specification of the PCM Stochastic Expression.
	 * 
	 *
	 * @param evaEx constant EvaluableExpression
	 * @return String specification of EvaluableExpression
	 */
	private String evaExToSpecification(final EvaluableExpression evaEx) {
		if (evaEx.getClass() == ConstantExpression.class) {
			return ((ConstantExpression) evaEx).getValue() + "";
		}
		return "";
	}
}
{'fraction_non_alphanumeric': 0.08125215790079411, 'fraction_numerical': 0.0, 'mean_word_length': 4.968406593406593, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5941223', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2554, 'n_words': 637}