analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / analysis / TmfAnalysisRequirementHelper.java
1 /*******************************************************************************
2 * Copyright (c) 2014 É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 * Contributors:
10 * Guilliano Molaire - Initial API and implementation
11 * Mathieu Rail - Initial API and implementation
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.core.analysis;
15
16 import java.util.HashSet;
17 import java.util.Set;
18
19 import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
20
21 import com.google.common.collect.HashMultimap;
22 import com.google.common.collect.SetMultimap;
23
24 /**
25 * Helper class to simplify analysis requirement management.
26 *
27 * @author Guilliano Molaire
28 */
29 public final class TmfAnalysisRequirementHelper {
30
31 /**
32 * Private constructor. The class should not be instantiated.
33 */
34 private TmfAnalysisRequirementHelper() {
35 }
36
37 /**
38 * Gets the requirement values of a given type from an analysis requirement
39 * provider. Only values linked to the type will be returned.
40 *
41 * @param provider
42 * The analysis requirement provider
43 * @param type
44 * The type of the requirement values we need
45 * @return The list of values for the specified type
46 */
47 public static Set<String> getRequirementValues(IAnalysisRequirementProvider provider, String type) {
48 Set<String> values = new HashSet<>();
49 for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
50 if (requirement.getType().equalsIgnoreCase(type)) {
51 values.addAll(requirement.getValues());
52 }
53 }
54 return values;
55 }
56
57 /**
58 * Gets the requirement values of a given type from an analysis requirement
59 * provider, with the specified level. Only values associated with that type
60 * and level will be returned.
61 *
62 * @param provider
63 * The analysis requirement provider
64 * @param type
65 * The type of the requirement values we need
66 * @param level
67 * The priority level of the values to be returned
68 * @return The list of values for the specified type
69 */
70 public static Set<String> getRequirementValues(IAnalysisRequirementProvider provider, String type, ValuePriorityLevel level) {
71 Set<String> values = new HashSet<>();
72 for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
73 if (requirement.getType().equalsIgnoreCase(type)) {
74 for (String value : requirement.getValues()) {
75 if (requirement.getValueLevel(value) == level) {
76 values.add(value);
77 }
78 }
79 }
80 }
81 return values;
82 }
83
84 /**
85 * Gets a map in which the keys are the types of different requirements and
86 * the values represent a set of requirement values linked to that type.
87 *
88 * @param providers
89 * The set of analysis requirement provider
90 * @return A map with the values keyed by type
91 */
92 public static SetMultimap<String, String> getRequirementValuesMap(Iterable<IAnalysisRequirementProvider> providers) {
93 SetMultimap<String, String> valuesByType = HashMultimap.create();
94 for (IAnalysisRequirementProvider provider : providers) {
95 for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
96 valuesByType.putAll(requirement.getType(), requirement.getValues());
97 }
98 }
99 return valuesByType;
100 }
101
102 /**
103 * Gets a map in which the keys are the types of different requirements and
104 * the values represents a list of requirement values linked to that type.
105 * We only take values with the same priority level as the argument.
106 *
107 * @param providers
108 * The set of analysis requirement provider
109 * @param level
110 * The priority level of the values to be returned
111 * @return A map with the values keyed by type
112 */
113 public static SetMultimap<String, String> getRequirementValuesMap(Iterable<IAnalysisRequirementProvider> providers, ValuePriorityLevel level) {
114 SetMultimap<String, String> valuesByType = HashMultimap.create();
115 for (IAnalysisRequirementProvider provider : providers) {
116 for (TmfAnalysisRequirement requirement : provider.getAnalysisRequirements()) {
117 /* Since it's a set, there will be no duplicate */
118 for (String value : requirement.getValues()) {
119 if (requirement.getValueLevel(value) == level) {
120 valuesByType.put(requirement.getType(), value);
121 }
122 }
123 }
124 }
125 return valuesByType;
126 }
127 }
This page took 0.088216 seconds and 5 git commands to generate.