This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
ResourceTypeUtility.java
87 lines (78 loc) · 3.26 KB
/
ResourceTypeUtility.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* RHQ Management Platform
* Copyright (C) 2012 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.rhq.core.domain.util;
import java.util.LinkedHashSet;
import java.util.Set;
import org.rhq.core.domain.measurement.MeasurementDefinition;
import org.rhq.core.domain.operation.OperationDefinition;
import org.rhq.core.domain.resource.ResourceType;
/**
* A set of utility methods for working with {@link ResourceType}s.
*
* @since 4.4
* @author Ian Springer
*/
public abstract class ResourceTypeUtility {
/**
* Returns the set of MeasurementDefinitions defined by the given Resource type, which are accepted by the specified
* filter. If the filter is null, all of the type's MeasurementDefinitions will be returned.
*
* @param type the Resource type
* @param filter the filter; may be null
*
* @return the set of MeasurementDefinition defined by the given Resource type, which are accepted by the specified
* filter, or, if the filter is null, all of the type's MeasurementDefinitions
*/
public static Set<MeasurementDefinition> getMeasurementDefinitions(ResourceType type,
MeasurementDefinitionFilter filter) {
if (filter == null) {
return type.getMetricDefinitions();
}
Set<MeasurementDefinition> acceptedMetricDefs = new LinkedHashSet<MeasurementDefinition>();
for (MeasurementDefinition metricDef : type.getMetricDefinitions()) {
if (filter.accept(metricDef)) {
acceptedMetricDefs.add(metricDef);
}
}
return acceptedMetricDefs;
}
public static MeasurementDefinition getMeasurementDefinition(ResourceType type, String metricName) {
for (MeasurementDefinition metricDefinition : type.getMetricDefinitions()) {
if (metricDefinition.getName().equals(metricName)) {
return metricDefinition;
}
}
return null;
}
public static OperationDefinition getOperationDefinition(ResourceType type, String operationName) {
for (OperationDefinition operationDefinition : type.getOperationDefinitions()) {
if (operationDefinition.getName().equals(operationName)) {
return operationDefinition;
}
}
return null;
}
public static String displayName(ResourceType resourceType) {
if (resourceType == null)
return null;
return resourceType.getDisplayName() == null ? resourceType.getName() : resourceType.getDisplayName();
}
private ResourceTypeUtility() {
}
}