6fc4c4f5291b0b215425972891e4d124474ba8bc
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / analysis / requirements / TmfAnalysisEventRequirement.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.tmf.core.analysis.requirements;
11
12 import java.util.Collection;
13 import java.util.Set;
14
15 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
16 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
17 import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
18
19 /**
20 * An analysis requirement for event names
21 *
22 * @author Geneviève Bastien
23 * @since 2.0
24 */
25 public class TmfAnalysisEventRequirement extends TmfAbstractAnalysisRequirement {
26
27 /**
28 * Constructor for an optional requirement
29 *
30 * TODO: The TYPE_EVENT should be removed and this class used instead
31 *
32 * @param eventNames
33 * The list of event names the trace must have
34 */
35 public TmfAnalysisEventRequirement(Collection<String> eventNames) {
36 super(eventNames, PriorityLevel.OPTIONAL);
37 }
38
39 /**
40 * Constructor. Instantiate a requirement object with a list of values of
41 * the same level
42 *
43 * @param eventNames
44 * The list of event names the trace must have
45 * @param level
46 * A level associated with all the values
47 */
48 public TmfAnalysisEventRequirement(Collection<String> eventNames, PriorityLevel level) {
49 super(eventNames, level);
50 }
51
52 @Override
53 public boolean test(ITmfTrace trace) {
54
55 if (!(trace instanceof ITmfTraceWithPreDefinedEvents)) {
56 return true;
57 }
58
59 Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(((ITmfTraceWithPreDefinedEvents) trace).getContainedEventTypes());
60 Set<String> values = getValues();
61
62 switch (getPriorityLevel()) {
63 case ALL_OR_NOTHING:
64 traceEvents.retainAll(values);
65 return (traceEvents.size() == 0 || traceEvents.size() == values.size());
66 case AT_LEAST_ONE:
67 traceEvents.retainAll(values);
68 return traceEvents.size() > 0;
69 case MANDATORY:
70 return traceEvents.containsAll(values);
71 case OPTIONAL:
72 return true;
73 default:
74 throw new IllegalStateException("Unknown value level: " + getPriorityLevel()); //$NON-NLS-1$
75 }
76 }
77
78 }
This page took 0.032636 seconds and 5 git commands to generate.