Top Description Constructors Methods
com.rometools.rome.io.impl

public final Class NumberParser

extends Object
Class Inheritance

A helper class that parses Numbers out of Strings in a lenient manner.

No method will throw any sort of Exception when parsing a string. All methods accept any Java String or null as legal input, if the input is non null, whitespace will be trimmed first, and then parsing will be attempted.

Constructor Summary

AccessConstructor and Description
private
NumberParser()

Private constructor to avoid NumberParser instances creation.

Method Summary

Modifier and TypeMethod and Description
public static Float

Returns:

The Float represented by the String, or null if it could not be parsed.
parseFloat
(final String
the String to parse
str
)

Parse a Float from a String without exceptions.

public static float
parseFloat(final String str, final float
the value to return if the String cannot be parsed
def
)

Parse a float from a String, with a default value

public static Integer

Returns:

The Integer represented by the String, or null if it could not be parsed.
parseInt
(final String
the String to parse
str
)

Parse an Integer from a String.

public static Long

Returns:

the Long represented by the given string, It returns null if it was not possible to parse the the string.
parseLong
(final String
string to parse for a Long.
str
)

Parses a Long out of a string.

public static long

Returns:

the long represented by the given string, or the default.
parseLong
(final String
string to parse for a long.
str
,
final long
default value to return if it is not possible to parse the the string.
def
)

Parses a long out of a string.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NumberParserback to summary
private NumberParser()

Private constructor to avoid NumberParser instances creation.

Method Detail

parseFloatback to summary
public static Float parseFloat(final String str)

Parse a Float from a String without exceptions. If the String is not a Float then null is returned

Parameters
str:String

the String to parse

Returns:Float

The Float represented by the String, or null if it could not be parsed.

parseFloatback to summary
public static float parseFloat(final String str, final float def)

Parse a float from a String, with a default value

Parameters
def:float

the value to return if the String cannot be parsed

parseIntback to summary
public static Integer parseInt(final String str)

Parse an Integer from a String. If the String is not an integer null is returned and no exception is thrown.

Parameters
str:String

the String to parse

Returns:Integer

The Integer represented by the String, or null if it could not be parsed.

parseLongback to summary
public static Long parseLong(final String str)

Parses a Long out of a string.

Parameters
str:String

string to parse for a Long.

Returns:Long

the Long represented by the given string, It returns null if it was not possible to parse the the string.

parseLongback to summary
public static long parseLong(final String str, final long def)

Parses a long out of a string.

Parameters
str:String

string to parse for a long.

def:long

default value to return if it is not possible to parse the the string.

Returns:long

the long represented by the given string, or the default.