Class DecimalUtil
- java.lang.Object
-
- host.fai.lib.faiNumber.DecimalUtil
-
public final class DecimalUtil extends Object
The
DecimalUtilclass is a final class that provides static methods for converting decimal values in string representation as bits to a Java's Primitive Data Type.Currently this class supports converting decimal values in string representation to integer int values and integer long values.
This class provides tools for comparing strings pertain to the mathematical aspect. This class provide the method
compareAsIntthat can compare strings by their actual digits values when the strings contain valid decimal values that can be parsed to integer int values.Strings can also be compared using the
intOrSmallermethod, of which compares the strings bases on their content reference to integer int values.Other method compareAs**** or ****OrSmaller(**** equals name) if available, are similar to the
compareAsIntorintOrSmallermethod, except they are for the "name(****)" type.This class only treats and parses decimal strings as signed values. To parses decimal values as signed or unsigned values, see
Base10Util.- Since:
- 1.0.0.f
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcompareAsInt(String firstNumber, String secondNumber)Compare two decimal number strings as integer int values.static intcompareAsLong(String firstNumber, String secondNumber)Compare two decimal number strings as integer long values.static intintOrSmaller(String firstNumber, String secondNumber)Compare two strings bases on the content of the strings reference to an integer int value.static intlongOrSmaller(String firstNumber, String secondNumber)Compare two strings bases on the content of the strings reference to an integer long value.static inttoInt(String input)Parse the input string as signed decimal number into an integer int value.static inttoIntTrueError(String input)Parse the input string as signed decimal number into an integer int value.static longtoLong(String input)Parse the input string as signed decimal number into an integer long value.static longtoLongTrueError(String input)Parse the input string as signed decimal number into an integer long value.
-
-
-
Method Detail
-
compareAsInt
public static int compareAsInt(String firstNumber, String secondNumber)
Compare two decimal number strings as integer int values. This method treat integer int values as signed integer type. This method does not throw errors. However, thetoIntmethod uses by this method throws errors.- Parameters:
firstNumber- A string to be compared to the stringsecondNumber.secondNumber- A string to be compared to the stringfirstNumber.- Returns:
- An integer int value of 1 if the
firstNumberstring is larger than thesecondNumberstring, 0 if they are both equal, or -1 if thefirstNumberstring is smaller than thesecondNumberstring. - Since:
- 1.0.0.f
- See Also:
toInt(String)
-
compareAsLong
public static int compareAsLong(String firstNumber, String secondNumber)
Compare two decimal number strings as integer long values. This method treat integer long values as signed integer type. This method does not throw errors. However, thetoLongmethod uses by this method throws errors.- Parameters:
firstNumber- A string to be compared to the stringsecondNumber.secondNumber- A string to be compared to the stringfirstNumber.- Returns:
- An integer int value of 1 if the
firstNumberstring is larger than thesecondNumberstring, 0 if they are both equal, or -1 if thefirstNumberstring is smaller than thesecondNumberstring. - Since:
- 1.0.0.f
- See Also:
toLong(String)
-
intOrSmaller
public static int intOrSmaller(String firstNumber, String secondNumber)
Compare two strings bases on the content of the strings reference to an integer int value. If the strings are valid decimal number strings that can be parse as integer int values then they will be compared bases on their integer int values. Otherwise, the strings will be compared bases on the priority ranking order below. This method treat integer int values as signed integer type.
Priority order ranking: (lo - hi) 0 - Invalid number strings 1 - Underflow 2 - Overflow 3 - Empty strings 4 - Valid int values
- Parameters:
firstNumber- A string to be compared to the stringsecondNumber.secondNumber- A string to be compared to the stringfirstNumber.- Returns:
- An integer int value of 1 if the
firstNumberstring is larger than thesecondNumberstring, 0 if they are both equal, or -1 if thefirstNumberstring is smaller than thesecondNumberstring. - Since:
- 1.0.0.f
-
longOrSmaller
public static int longOrSmaller(String firstNumber, String secondNumber)
Compare two strings bases on the content of the strings reference to an integer long value. If the strings are valid decimal number strings that can be parse as integer long values then they will be compared bases on their integer long values. Otherwise, the strings will be compared bases on the priority ranking order below. This method treat integer long values as signed integer type.
Priority order ranking: (lo - hi) 0 - Invalid number strings 1 - Underflow 2 - Overflow 3 - Empty strings 4 - Valid long values
- Parameters:
firstNumber- A string to be compared to the stringsecondNumber.secondNumber- A string to be compared to the stringfirstNumber.- Returns:
- An integer int value of 1 if the
firstNumberstring is larger than thesecondNumberstring, 0 if they are both equal, or -1 if thefirstNumberstring is smaller than thesecondNumberstring. - Since:
- 1.0.0.f
-
toInt
public static final int toInt(String input)
Parse the input string as signed decimal number into an integer int value.- Parameters:
input- A string to be parsed as signed decimal number to an integer int value.- Returns:
- An integer int value of the signed decimal string.
inputstring. - Throws:
NumberFormatException- If theinputstring contains invalid signed decimal digits, if theinputstring contains a value that is smaller than the value of Integer.MIN_VALUE(-2147483648), or if theinputstring contains a value that is larger than the value of Integer.MAX_VALUE( 2147483647).EmptyStringException- If theinputstring is empty.- Since:
- 1.0.0.f
-
toIntTrueError
public static final int toIntTrueError(String input)
Parse the input string as signed decimal number into an integer int value. This method throws true errors on unsuccessful parse cases. This method may take longer on unsucessful parse cases.- Parameters:
input- A string to be parsed as signed decimal number to an integer int value.- Returns:
- An integer int value of the signed decimal string
inputstring. - Throws:
NumberFormatException- If theinputstring contains invalid signed decimal digits.NumberUnderFlowException- If theinputstring contains a value that is smaller than the value of Integer.MIN_VALUE( -2147483648).NumberOverFlowException- If theinputstring contains a value that is larger than the value of Integer.MAX_VALUE( 2147483647).EmptyStringException- If theinputstring is empty.- Since:
- 1.0.0.f
-
toLong
public static final long toLong(String input)
Parse the input string as signed decimal number into an integer long value.- Parameters:
input- A string to be parsed as signed decimal number to an integer long value.- Returns:
- An integer long value of the signed decimal
inputstring. - Throws:
NumberFormatException- If theinputstring contains invalid signed decimal digits, if theinputstring contains a value that is smaller than the value of Long.MIN_VALUE( -9223372036854775808L), or if theinputstring contains a value that is larger than the value of Long.MAX_VALUE( 9223372036854775807L).EmptyStringException- If theinputstring is empty.- Since:
- 1.0.0.f
-
toLongTrueError
public static final long toLongTrueError(String input)
Parse the input string as signed decimal number into an integer long value. This method throws true errors on unsuccessful parse cases. This method may take longer on unsucessful parse cases.- Parameters:
input- A string to be parsed as signed decimal number to an integer long value.- Returns:
- An integer long value of the signed decimal
inputstring. - Throws:
NumberFormatException- If theinputstring contains invalid decimal digits.NumberUnderFlowException- If theinputstring contains a value that is smaller than the value of Long.MIN_VALUE( -9223372036854775808L).NumberOverFlowException- If theinputstring contains a value that is larger than the value of Long.MAX_VALUE( 9223372036854775807L).EmptyStringException- If theinputstring is empty.- Since:
- 1.0.0.f
-
-