requirements: make TmfAnalysisRequirement abstract
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / trace / KernelEventLayoutRequirement.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.analysis.os.linux.core.trace;
11
12 import java.util.Set;
13
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAnalysisEventRequirement;
16 import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement;
17 import org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement.PriorityLevel;
18
19 import com.google.common.collect.ImmutableList.Builder;
20
21 /**
22 * This class is a pre-requirement class who will instanciate at runtime the
23 * actual requirements depending on a trace's event layout
24 *
25 * @author Geneviève Bastien
26 * @since 2.0
27 */
28 public class KernelEventLayoutRequirement {
29
30 /**
31 * Functional interface that maps a layout to an event name
32 */
33 @FunctionalInterface
34 public interface ILayoutToEventName {
35 /**
36 * This method will return the event name mapped by this requirement
37 * from the layout. The returned event name may be <code>null</code> in
38 * some layouts.
39 *
40 * @param layout
41 * The event layout of the trace
42 * @return The event name
43 */
44 @Nullable String getEventName(IKernelAnalysisEventLayout layout);
45 }
46
47 private final Set<ILayoutToEventName> fEventNames;
48 private final PriorityLevel fLevel;
49
50 /**
51 * Constructor
52 *
53 * @param layoutReqs
54 * The layout mappings this requirement represents
55 * @param level
56 * Whether the requirement represented by these mapping is
57 * mandatory or optional
58 */
59 public KernelEventLayoutRequirement(Set<ILayoutToEventName> layoutReqs, PriorityLevel level) {
60 fEventNames = layoutReqs;
61 fLevel = level;
62 }
63
64 /**
65 * Build a real requirement from the layout mapping to be matched with a
66 * real trace's layout
67 *
68 * @param layout
69 * The event layout from which to build the requirements.
70 * @return The real requirement
71 */
72 public TmfAbstractAnalysisRequirement instanciateRequirements(IKernelAnalysisEventLayout layout) {
73 Builder<String> events = new Builder<>();
74 for (ILayoutToEventName eventNameLayout : fEventNames) {
75 String eventName = eventNameLayout.getEventName(layout);
76 if (eventName != null) {
77 events.add(eventName);
78 }
79 }
80 return new TmfAnalysisEventRequirement(events.build(), fLevel);
81 }
82
83 }
This page took 0.032403 seconds and 5 git commands to generate.