org.rhq.core.util
Class NumberUtil

java.lang.Object
  extended by org.rhq.core.util.NumberUtil

public final class NumberUtil
extends Object

Utilities for dealing with number parsing / formatting. This class is mainly meant to be used by java beans and other classes that must do number formatting but cannot throw any exceptions during the process.


Field Summary
static Number NaN
          Constant value representing "not a number".
 
Method Summary
static String autoIncrementVersion(String oldVersion)
          Given an old version string, this attempts to auto-generate a new incremented version.
static String numberAsString(double input)
          Format the input number as a string (using the default locale).
static String percentageAsString(double input)
          Format the input percentage as a string (using the default locale).
static Number stringAsNumber(String input)
          Parse the input string (using the default locale) and return its numeric representation.
static Number stringAsPercentage(String input)
          Parse the input string (using the default locale) and return its numeric percentage representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NaN

public static final Number NaN
Constant value representing "not a number".

Method Detail

stringAsNumber

public static Number stringAsNumber(String input)
Parse the input string (using the default locale) and return its numeric representation. If the input string is null, empty or cannot be parsed, return Double.NaN .


numberAsString

public static String numberAsString(double input)
Format the input number as a string (using the default locale). If the input number is Double.NaN, return null.


stringAsPercentage

public static Number stringAsPercentage(String input)
Parse the input string (using the default locale) and return its numeric percentage representation. If the input string is null, empty or cannot be parsed, return Double.NaN .


percentageAsString

public static String percentageAsString(double input)
Format the input percentage as a string (using the default locale). If the input percentage is Double.NaN, return null.


autoIncrementVersion

public static String autoIncrementVersion(String oldVersion)
Given an old version string, this attempts to auto-generate a new incremented version.

Parameters:
oldVersion - the version to increment
Returns:
the auto-incremented version


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.