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