blob: 86f3772a47ff2990fec87ec71f8022c23a583d7d [file] [log] [blame]
Jian Li4df75b12018-06-07 22:11:04 +09001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstacktelemetry.util;
17
18import com.google.common.base.Strings;
19
20import java.util.Dictionary;
21
22import static org.onlab.util.Tools.get;
23
24/**
25 * An utility that used in openstack telemetry app.
26 */
27public final class OpenstackTelemetryUtil {
28
29 /**
30 * Prevents object instantiation from external.
31 */
32 private OpenstackTelemetryUtil() {
33 }
34
35 /**
36 * Gets Boolean property from the propertyName
37 * Return null if propertyName is not found.
38 *
39 * @param properties properties to be looked up
40 * @param propertyName the name of the property to look up
41 * @return value when the propertyName is defined or return null
42 */
43 public static Boolean getBooleanProperty(Dictionary<?, ?> properties,
44 String propertyName) {
45 Boolean value;
46 try {
47 String s = get(properties, propertyName);
48 value = Strings.isNullOrEmpty(s) ? null : Boolean.valueOf(s);
49 } catch (ClassCastException e) {
50 value = null;
51 }
52 return value;
53 }
54}