requirements: Clean up the API of TmfAnalysisRequirement
[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.Collections;
14 import java.util.Set;
15
16 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
17 import org.eclipse.tracecompass.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
18 import org.eclipse.tracecompass.tmf.core.trace.TmfEventTypeCollectionHelper;
19
20 /**
21 * An analysis requirement for event names
22 *
23 * @author Geneviève Bastien
24 * @since 2.0
25 */
26 public class TmfAnalysisEventRequirement extends TmfAnalysisRequirement {
27
28 /**
29 * Constructor for an optional requirement
30 *
31 * TODO: The TYPE_EVENT should be removed and this class used instead
32 *
33 * @param eventNames
34 * The list of event names the trace must have
35 */
36 public TmfAnalysisEventRequirement(Collection<String> eventNames) {
37 super(eventNames, PriorityLevel.OPTIONAL);
38 }
39
40 /**
41 * Constructor. Instantiate a requirement object with a list of values of
42 * the same level
43 *
44 * @param eventNames
45 * The list of event names the trace must have
46 * @param level
47 * A level associated with all the values
48 */
49 public TmfAnalysisEventRequirement(Collection<String> eventNames, PriorityLevel level) {
50 super(eventNames, level);
51 }
52
53 @Override
54 public boolean test(ITmfTrace trace) {
55
56 // TODO: implement for all levels
57 if (trace instanceof ITmfTraceWithPreDefinedEvents) {
58 Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(((ITmfTraceWithPreDefinedEvents) trace).getContainedEventTypes());
59 Set<String> mandatoryValues = getPriorityLevel().equals(PriorityLevel.MANDATORY) ? getValues() : Collections.EMPTY_SET;
60 return traceEvents.containsAll(mandatoryValues);
61 }
62
63 return true;
64 }
65
66 }
This page took 0.0541 seconds and 6 git commands to generate.