| 1 | package de.uka.ipd.sdq.stoex.analyser.operations; |
| 2 | |
| 3 | import de.uka.ipd.sdq.probfunction.math.IProbabilityDensityFunction; |
| 4 | import de.uka.ipd.sdq.probfunction.math.IProbabilityMassFunction; |
| 5 | import de.uka.ipd.sdq.probfunction.math.exception.DomainNotNumbersException; |
| 6 | import de.uka.ipd.sdq.probfunction.math.exception.FunctionsInDifferenDomainsException; |
| 7 | import de.uka.ipd.sdq.probfunction.math.exception.IncompatibleUnitsException; |
| 8 | import de.uka.ipd.sdq.probfunction.math.exception.UnknownPDFTypeException; |
| 9 | |
| 10 | /** |
| 11 | * Implements the operation "multiplication" for different kinds of operands. |
| 12 | * @author martens, koziolek |
| 13 | */ |
| 14 | public class MultOperation extends TermProductOperation { |
| 15 | |
| 16 | @Override |
| 17 | public double compute(double left, double right) { |
| 18 | return left*right; |
| 19 | } |
| 20 | |
| 21 | @Override |
| 22 | public int compute(int left, int right) { |
| 23 | return left*right; |
| 24 | } |
| 25 | |
| 26 | @Override |
| 27 | public IProbabilityMassFunction compute(IProbabilityMassFunction left, |
| 28 | double right) throws DomainNotNumbersException { |
| 29 | if (right == 0){ |
| 30 | throw new IllegalArgumentException("ProbabilityMassFunction "+left.toString()+" cannot be multiplied with 0, this operation is undefined."); |
| 31 | } |
| 32 | return left.stretchDomain(right); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | |
| 37 | @Override |
| 38 | public IProbabilityDensityFunction compute(IProbabilityDensityFunction left, double right) throws DomainNotNumbersException { |
| 39 | if (right == 0){ |
| 40 | throw new IllegalArgumentException("ProbabilityDensityFunction "+left.toString()+" cannot be multiplied with 0, this operation is undefined."); |
| 41 | } |
| 42 | return left.stretchDomain(right); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | protected Double calculateOperationForValues(Double value1, Double value2) { |
| 47 | return value1 * value2; |
| 48 | } |
| 49 | |
| 50 | } |