1 /*******************************************************************************
2 * Copyright (c) 2014 É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
10 * Guilliano Molaire - Initial API and implementation
11 * Mathieu Rail - Initial API and implementation
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.core
.analysis
;
16 import java
.util
.HashSet
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisRequirement
.ValuePriorityLevel
;
21 import com
.google
.common
.collect
.HashMultimap
;
22 import com
.google
.common
.collect
.SetMultimap
;
25 * Helper class to simplify analysis requirement management.
27 * @author Guilliano Molaire
29 public final class TmfAnalysisRequirementHelper
{
32 * Private constructor. The class should not be instantiated.
34 private TmfAnalysisRequirementHelper() {
38 * Gets the requirement values of a given type from an analysis requirement
39 * provider. Only values linked to the type will be returned.
42 * The analysis requirement provider
44 * The type of the requirement values we need
45 * @return The list of values for the specified type
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());
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.
63 * The analysis requirement provider
65 * The type of the requirement values we need
67 * The priority level of the values to be returned
68 * @return The list of values for the specified type
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
) {
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.
89 * The set of analysis requirement provider
90 * @return A map with the values keyed by type
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());
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.
108 * The set of analysis requirement provider
110 * The priority level of the values to be returned
111 * @return A map with the values keyed by type
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
);