1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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
;
13 import java
.util
.Collections
;
16 import org
.eclipse
.jdt
.annotation
.NonNull
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTraceWithPreDefinedEvents
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfEventTypeCollectionHelper
;
21 import com
.google
.common
.collect
.Multimap
;
24 * An analysis requirement for event fields of a given event name.
26 * @author Bernd Hufmann
29 public class TmfAnalysisEventFieldRequirement
extends TmfAbstractAnalysisRequirement
{
31 /** The event name of the event containing the mandatory fields */
32 private String fEventName
;
38 * The event name of the event containing the mandatory fields.
39 * Empty string will indicate that all events need to have the
42 * The list of event field names the trace must have
44 public TmfAnalysisEventFieldRequirement(String eventName
, Collection
<String
> fields
) {
45 this(eventName
, fields
, PriorityLevel
.OPTIONAL
);
49 * Constructor. Instantiate a requirement object with a list of values of
53 * The event name of the event containing the mandatory fields.
54 * Empty string will indicate that all events need to have the
57 * The list of event field names the trace must have
59 * A level associated with all the values
60 * @throws IllegalArgumentException if no event names are provided
62 public TmfAnalysisEventFieldRequirement(String eventName
, Collection
<String
> fields
, PriorityLevel level
) {
64 fEventName
= eventName
;
68 public boolean test(ITmfTrace trace
) {
69 if ((trace
instanceof ITmfTraceWithPreDefinedEvents
)) {
70 // TODO Implement for all levels of requirements
71 Set
<String
> mandatoryValues
= getPriorityLevel().equals(PriorityLevel
.MANDATORY
) ?
getValues() : Collections
.EMPTY_SET
;
72 if (mandatoryValues
.isEmpty()) {
75 Multimap
<@NonNull String
, @NonNull String
> traceEvents
=
76 TmfEventTypeCollectionHelper
.getEventFieldNames((((ITmfTraceWithPreDefinedEvents
) trace
).getContainedEventTypes()));
78 if (fEventName
.isEmpty()) {
79 return traceEvents
.keys().stream().allMatch(eventName
-> {
80 Collection
<@NonNull String
> fields
= traceEvents
.get(fEventName
);
81 return fields
.containsAll(mandatoryValues
);
84 Collection
<@NonNull String
> fields
= traceEvents
.get(fEventName
);
85 return fields
.containsAll(mandatoryValues
);