dcc05a8e58862d9f024493c4f1d877a89e4edb04
[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.Set;
13
14 import org.eclipse.jdt.annotation.NonNull;
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 TmfAnalysisRequirement {
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(Iterable<String> eventNames) {
36 super(TmfAnalysisRequirement.TYPE_EVENT, eventNames, ValuePriorityLevel.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(Iterable<String> eventNames, ValuePriorityLevel level) {
49 super(TmfAnalysisRequirement.TYPE_EVENT, eventNames, level);
50 }
51
52 @Override
53 public boolean isFulfilled(@NonNull ITmfTrace trace) {
54
55 if (trace instanceof ITmfTraceWithPreDefinedEvents) {
56 Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(((ITmfTraceWithPreDefinedEvents) trace).getContainedEventTypes());
57 Set<String> mandatoryValues = getValues(ValuePriorityLevel.MANDATORY);
58 return traceEvents.containsAll(mandatoryValues);
59 }
60
61 return true;
62 }
63
64 }
This page took 0.032864 seconds and 4 git commands to generate.