| 1 | package de.uka.ipd.sdq.probespec.framework.calculator; |
| 2 | |
| 3 | import java.util.Vector; |
| 4 | |
| 5 | import javax.measure.Measure; |
| 6 | import javax.measure.quantity.Quantity; |
| 7 | |
| 8 | import de.uka.ipd.sdq.pipesandfilters.framework.MeasurementMetric; |
| 9 | import de.uka.ipd.sdq.probespec.framework.BlackboardVote; |
| 10 | import de.uka.ipd.sdq.probespec.framework.ProbeSetSample; |
| 11 | import de.uka.ipd.sdq.probespec.framework.ProbeSpecContext; |
| 12 | import de.uka.ipd.sdq.probespec.framework.exceptions.CalculatorException; |
| 13 | |
| 14 | public abstract class UnaryCalculator extends Calculator { |
| 15 | |
| 16 | private Integer probeSetID; |
| 17 | |
| 18 | protected UnaryCalculator(ProbeSpecContext ctx, Integer probeSetID) { |
| 19 | super(ctx); |
| 20 | this.probeSetID = probeSetID; |
| 21 | |
| 22 | ctx.getSampleBlackboard().addBlackboardListener(this, probeSetID); |
| 23 | } |
| 24 | |
| 25 | abstract protected Vector<Measure<?, ? extends Quantity>> calculate( |
| 26 | ProbeSetSample sample) |
| 27 | throws CalculatorException; |
| 28 | |
| 29 | @Override |
| 30 | abstract protected Vector<MeasurementMetric> getConcreteMeasurementMetrics(); |
| 31 | |
| 32 | @Override |
| 33 | protected BlackboardVote execute(ProbeSetSample pss) throws CalculatorException { |
| 34 | if (probeSetID.equals(pss.getProbeSetAndRequestContext().getProbeSetID())) { |
| 35 | Vector<Measure<?, ? extends Quantity>> resultTuple = calculate(pss); |
| 36 | fireCalculated(resultTuple); |
| 37 | } |
| 38 | return BlackboardVote.DISCARD; |
| 39 | } |
| 40 | |
| 41 | } |