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 org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
14 import com.google.common.base.Strings;
17 * Provides utilities for system properties.
19 * @author Thomas Pantelis
21 public final class PropertyUtils {
23 private static final Logger LOG = LoggerFactory.getLogger(PropertyUtils.class);
25 private PropertyUtils() {
29 * Obtains the given property from the System properties and returns as an int. If the property
30 * is not found the specified default value is returned. If the property value can't be parsed
31 * to an int, a warning is logged and the default value is returned.
33 * @param propName the name of the property to get
34 * @param defaultValue the default value
35 * @return the System property as an int or the <code>defaultValue</code> if not found.
37 public static int getIntSystemProperty( String propName, int defaultValue ) {
38 int propValue = defaultValue;
39 String strValue = System.getProperty(propName);
40 if (!Strings.isNullOrEmpty(strValue) && !strValue.trim().isEmpty() ) {
42 propValue = Integer.parseInt(strValue);
43 } catch (NumberFormatException e) {
44 LOG.warn("Cannot parse value {} for system property {}, using default {}",
45 strValue, propName, defaultValue);