1 | package de.uka.ipd.sdq.probespec.framework.probes.example; |
2 | |
3 | import javax.measure.Measure; |
4 | import javax.measure.quantity.Dimensionless; |
5 | |
6 | import de.uka.ipd.sdq.probespec.framework.ProbeSample; |
7 | import de.uka.ipd.sdq.probespec.framework.ProbeType; |
8 | import de.uka.ipd.sdq.probespec.framework.probes.IProbeStrategy; |
9 | |
10 | public class ExampleTakeSEFFParameterStrategy implements IProbeStrategy { |
11 | |
12 | /** |
13 | * @param o |
14 | * expects a {@link SimpleSEFFParameter} |
15 | */ |
16 | @SuppressWarnings("unchecked") |
17 | @Override |
18 | public ProbeSample<?, Dimensionless> takeSample(String probeId, Object... o) { |
19 | SimpleSEFFParameter<?> parameter; |
20 | if (o[0] instanceof SimpleSEFFParameter) { |
21 | parameter = (SimpleSEFFParameter<?>) o[0]; |
22 | } else { |
23 | throw new IllegalArgumentException("Expected an argument of type " |
24 | + SimpleSEFFParameter.class.getSimpleName() + "."); |
25 | } |
26 | |
27 | ProbeSample<?, Dimensionless> sample = null; |
28 | if (parameter.getValue() instanceof Double) { |
29 | Measure<Double, Dimensionless> value = Measure.valueOf( |
30 | (Double) parameter.getValue(), Dimensionless.UNIT); |
31 | sample = new ProbeSample<Double, Dimensionless>(value, probeId, |
32 | ProbeType.SEFF_PARAMETER); |
33 | } else if (parameter.getValue() instanceof Float) { |
34 | Measure<Float, Dimensionless> value = Measure.valueOf( |
35 | (Float) parameter.getValue(), Dimensionless.UNIT); |
36 | sample = new ProbeSample<Float, Dimensionless>(value, probeId, |
37 | ProbeType.SEFF_PARAMETER); |
38 | } else if (parameter.getValue() instanceof Integer) { |
39 | Measure<Integer, Dimensionless> value = Measure.valueOf( |
40 | (Integer) parameter.getValue(), Dimensionless.UNIT); |
41 | sample = new ProbeSample<Integer, Dimensionless>(value, probeId, |
42 | ProbeType.SEFF_PARAMETER); |
43 | } else if (parameter.getValue() instanceof Long) { |
44 | Measure<Long, Dimensionless> value = Measure.valueOf( |
45 | (Long) parameter.getValue(), Dimensionless.UNIT); |
46 | sample = new ProbeSample<Long, Dimensionless>(value, probeId, |
47 | ProbeType.SEFF_PARAMETER); |
48 | } else { |
49 | throw new IllegalArgumentException( |
50 | "Expected an argument containing a value of type Double, Float, Integer or Long."); |
51 | } |
52 | |
53 | return sample; |
54 | } |
55 | } |