1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.core
.analysis
.requirements
;
12 import java
.util
.Collection
;
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
;
20 * An analysis requirement for event names
22 * @author Geneviève Bastien
25 public class TmfAnalysisEventRequirement
extends TmfAbstractAnalysisRequirement
{
28 * Constructor for an optional requirement
30 * TODO: The TYPE_EVENT should be removed and this class used instead
33 * The list of event names the trace must have
35 public TmfAnalysisEventRequirement(Collection
<String
> eventNames
) {
36 super(eventNames
, PriorityLevel
.OPTIONAL
);
40 * Constructor. Instantiate a requirement object with a list of values of
44 * The list of event names the trace must have
46 * A level associated with all the values
48 public TmfAnalysisEventRequirement(Collection
<String
> eventNames
, PriorityLevel level
) {
49 super(eventNames
, level
);
53 public boolean test(ITmfTrace trace
) {
55 if (!(trace
instanceof ITmfTraceWithPreDefinedEvents
)) {
59 Set
<String
> traceEvents
= TmfEventTypeCollectionHelper
.getEventNames(((ITmfTraceWithPreDefinedEvents
) trace
).getContainedEventTypes());
60 Set
<String
> values
= getValues();
62 switch (getPriorityLevel()) {
64 traceEvents
.retainAll(values
);
65 return (traceEvents
.size() == 0 || traceEvents
.size() == values
.size());
67 traceEvents
.retainAll(values
);
68 return traceEvents
.size() > 0;
70 return traceEvents
.containsAll(values
);
74 throw new IllegalStateException("Unknown value level: " + getPriorityLevel()); //$NON-NLS-1$