2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.util;
11 import com.google.common.base.Strings;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
16 * Provides utilities for system properties.
18 * @author Thomas Pantelis
20 public final class PropertyUtils {
22 private static final Logger LOG = LoggerFactory.getLogger(PropertyUtils.class);
24 private PropertyUtils() {
28 * Obtains the given property from the System properties and returns as an int. If the property
29 * is not found the specified default value is returned. If the property value can't be parsed
30 * to an int, a warning is logged and the default value is returned.
32 * @param propName the name of the property to get
33 * @param defaultValue the default value
34 * @return the System property as an int or the <code>defaultValue</code> if not found.
36 public static int getIntSystemProperty(String propName, int defaultValue) {
37 int propValue = defaultValue;
38 String strValue = System.getProperty(propName);
39 if (!Strings.isNullOrEmpty(strValue) && !strValue.trim().isEmpty()) {
41 propValue = Integer.parseInt(strValue);
42 } catch (NumberFormatException e) {
43 LOG.warn("Cannot parse value {} for system property {}, using default {}",
44 strValue, propName, defaultValue);