1 | package de.uka.ipd.sdq.sensorframework.filter; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Collection; |
5 | import java.util.Collections; |
6 | import java.util.Comparator; |
7 | import java.util.Iterator; |
8 | |
9 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
10 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanMeasurement; |
11 | import de.uka.ipd.sdq.sensorframework.filter.AbstractMeasurementsCollection; |
12 | |
13 | public class OutlierFilteredCollection extends AbstractMeasurementsCollection { |
14 | |
15 | /** The configurations parameter. */ |
16 | private double parameter; |
17 | |
18 | /** |
19 | * Initializes a new OutlierFilteredCollection with the given measurements and filter parameter. |
20 | * |
21 | * @param originalMeasurements |
22 | * The associated measurements. |
23 | * @param parameter The associated parameter |
24 | */ |
25 | public OutlierFilteredCollection( |
26 | Collection<Measurement> originalMeasurements, double parameter) { |
27 | super(originalMeasurements); |
28 | this.parameter = parameter; |
29 | } |
30 | |
31 | /** {@inheritDoc} |
32 | */ |
33 | @Override |
34 | protected void applyFilter(Collection<Measurement> filteredItemsList) { |
35 | int outlierNumber = 0; |
36 | outlierNumber = (int) (parameter * originalMeasurements.size()); |
37 | ArrayList<TimeSpanMeasurement> sortedMeasurements = (ArrayList<TimeSpanMeasurement>) new ArrayList<TimeSpanMeasurement>(); |
38 | for (Iterator<?> it = originalMeasurements.iterator(); it.hasNext();) |
39 | sortedMeasurements.add((TimeSpanMeasurement) it.next()); |
40 | Collections.sort(sortedMeasurements, |
41 | new Comparator<TimeSpanMeasurement>() { |
42 | |
43 | public int compare(TimeSpanMeasurement o1, |
44 | TimeSpanMeasurement o2) { |
45 | return Double.compare(o1.getTimeSpan(), o2 |
46 | .getTimeSpan()); |
47 | } |
48 | |
49 | }); |
50 | for (int i = sortedMeasurements.size() - 1; i >= sortedMeasurements |
51 | .size() |
52 | - outlierNumber; i--) { |
53 | filteredItemsList.add(sortedMeasurements.get(i)); |
54 | } |
55 | } |
56 | } |