d9acbf8fce0b26dd0c812b515d8e42ab407f825e
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / analysis / requirements / TmfAnalysisEventFieldRequirement.java
1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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.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;
20
21 import com.google.common.collect.Multimap;
22
23 /**
24 * An analysis requirement for event fields of a given event name.
25 *
26 * @author Bernd Hufmann
27 * @since 2.0
28 */
29 public class TmfAnalysisEventFieldRequirement extends TmfAbstractAnalysisRequirement {
30
31 /** The event name of the event containing the mandatory fields */
32 private String fEventName;
33
34 /**
35 * Constructor
36 *
37 * @param eventName
38 * The event name of the event containing the mandatory fields.
39 * Empty string will indicate that all events need to have the
40 * fields.
41 * @param fields
42 * The list of event field names the trace must have
43 */
44 public TmfAnalysisEventFieldRequirement(String eventName, Collection<String> fields) {
45 this(eventName, fields, PriorityLevel.OPTIONAL);
46 }
47
48 /**
49 * Constructor. Instantiate a requirement object with a list of values of
50 * the same level
51 *
52 * @param eventName
53 * The event name of the event containing the mandatory fields.
54 * Empty string will indicate that all events need to have the
55 * fields.
56 * @param fields
57 * The list of event field names the trace must have
58 * @param level
59 * A level associated with all the values
60 * @throws IllegalArgumentException if no event names are provided
61 */
62 public TmfAnalysisEventFieldRequirement(String eventName, Collection<String> fields, PriorityLevel level) {
63 super(fields, level);
64 fEventName = eventName;
65 }
66
67 @Override
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()) {
73 return true;
74 }
75 Multimap<@NonNull String, @NonNull String> traceEvents =
76 TmfEventTypeCollectionHelper.getEventFieldNames((((ITmfTraceWithPreDefinedEvents) trace).getContainedEventTypes()));
77
78 if (fEventName.isEmpty()) {
79 return traceEvents.keys().stream().allMatch(eventName -> {
80 Collection<@NonNull String> fields = traceEvents.get(fEventName);
81 return fields.containsAll(mandatoryValues);
82 });
83 }
84 Collection<@NonNull String> fields = traceEvents.get(fEventName);
85 return fields.containsAll(mandatoryValues);
86 }
87 return true;
88 }
89
90 }
This page took 0.096396 seconds and 4 git commands to generate.