Example usage for org.apache.commons.lang3.math NumberUtils toShort

List of usage examples for org.apache.commons.lang3.math NumberUtils toShort

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils toShort.

Prototype

public static short toShort(final String str, final short defaultValue) 

Source Link

Document

Convert a String to an short, returning a default value if the conversion fails.

If the string is null, the default value is returned.

 NumberUtils.toShort(null, 1) = 1 NumberUtils.toShort("", 1)   = 1 NumberUtils.toShort("1", 0)  = 1 

Usage

From source file:ezbake.common.properties.EzProperties.java

/**
 * Get a property as a short, if the property doesn't exist or can't be converted then we return the default value
 *
 * @param propertyName is the name of the property we are looking for (the key)
 * @param defaultValue is the value to return if the key doesn't exist or the value can't be converted to a short
 *
 * @return either the properly parsed short or the default value if the key doesn't exist or can't be converted
 *///from   w  w  w. jav a2 s.  c  o m
public short getShort(String propertyName, short defaultValue) {
    return NumberUtils.toShort(getProperty(propertyName), defaultValue);
}