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
.linuxtools
.tmf
.core
.analysis
;
16 import java
.util
.HashSet
;
19 import org
.eclipse
.linuxtools
.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
30 public final class TmfAnalysisRequirementHelper
{
33 * Private constructor. The class should not be instantiated.
35 private TmfAnalysisRequirementHelper() {
39 * Gets the requirement values of a given type from an analysis requirement
40 * provider. Only values linked to the type will be returned.
43 * The analysis requirement provider
45 * The type of the requirement values we need
46 * @return The list of values for the specified type
48 public static Set
<String
> getRequirementValues(IAnalysisRequirementProvider provider
, String type
) {
49 Set
<String
> values
= new HashSet
<>();
50 for (TmfAnalysisRequirement requirement
: provider
.getAnalysisRequirements()) {
51 if (requirement
.getType().equalsIgnoreCase(type
)) {
52 values
.addAll(requirement
.getValues());
59 * Gets the requirement values of a given type from an analysis requirement
60 * provider, with the specified level. Only values associated with that type
61 * and level will be returned.
64 * The analysis requirement provider
66 * The type of the requirement values we need
68 * The priority level of the values to be returned
69 * @return The list of values for the specified type
71 public static Set
<String
> getRequirementValues(IAnalysisRequirementProvider provider
, String type
, ValuePriorityLevel level
) {
72 Set
<String
> values
= new HashSet
<>();
73 for (TmfAnalysisRequirement requirement
: provider
.getAnalysisRequirements()) {
74 if (requirement
.getType().equalsIgnoreCase(type
)) {
75 for (String value
: requirement
.getValues()) {
76 if (requirement
.getValueLevel(value
) == level
) {
86 * Gets a map in which the keys are the types of different requirements and
87 * the values represent a set of requirement values linked to that type.
90 * The set of analysis requirement provider
91 * @return A map with the values keyed by type
93 public static SetMultimap
<String
, String
> getRequirementValuesMap(Iterable
<IAnalysisRequirementProvider
> providers
) {
94 SetMultimap
<String
, String
> valuesByType
= HashMultimap
.create();
95 for (IAnalysisRequirementProvider provider
: providers
) {
96 for (TmfAnalysisRequirement requirement
: provider
.getAnalysisRequirements()) {
97 valuesByType
.putAll(requirement
.getType(), requirement
.getValues());
104 * Gets a map in which the keys are the types of different requirements and
105 * the values represents a list of requirement values linked to that type.
106 * We only take values with the same priority level as the argument.
109 * The set of analysis requirement provider
111 * The priority level of the values to be returned
112 * @return A map with the values keyed by type
114 public static SetMultimap
<String
, String
> getRequirementValuesMap(Iterable
<IAnalysisRequirementProvider
> providers
, ValuePriorityLevel level
) {
115 SetMultimap
<String
, String
> valuesByType
= HashMultimap
.create();
116 for (IAnalysisRequirementProvider provider
: providers
) {
117 for (TmfAnalysisRequirement requirement
: provider
.getAnalysisRequirements()) {
118 /* Since it's a set, there will be no duplicate */
119 for (String value
: requirement
.getValues()) {
120 if (requirement
.getValueLevel(value
) == level
) {
121 valuesByType
.put(requirement
.getType(), value
);