Package me.datafox.dfxengine.math.utils
Class Conversion
java.lang.Object
me.datafox.dfxengine.math.utils.Conversion
Various conversion methods for
Numerals.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimalstatic BigDecNumeraltoBigDecNumeral(Numeral numeral) static BigIntegerstatic BigIntNumeraltoBigIntNumeral(Numeral numeral) static Numeralstatic doublestatic DoubleNumeraltoDoubleNumeral(Numeral numeral) static floatstatic FloatNumeraltoFloatNumeral(Numeral numeral) static intstatic Numeralstatic IntNumeraltoIntNumeral(Numeral numeral) static longstatic LongNumeraltoLongNumeral(Numeral numeral) static NumeraltoNumeral(Numeral numeral, NumeralType type) static NumeraltoSmallestType(Numeral numeral)
-
Constructor Details
-
Conversion
public Conversion()
-
-
Method Details
-
toInt
- Parameters:
numeral-Numeralto be converted- Returns:
intrepresentation of the specified value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller thanInteger.MIN_VALUEor greater thanInteger.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toLong
- Parameters:
numeral-Numeralto be converted- Returns:
longrepresentation of the specified value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller thanLong.MIN_VALUEor greater thanLong.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toBigInt
- Parameters:
numeral-Numeralto be converted- Returns:
BigIntegerrepresentation of the specified value- Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toFloat
- Parameters:
numeral-Numeralto be converted- Returns:
floatrepresentation of the specified value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller than-Float.MAX_VALUEor greater thanFloat.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toDouble
- Parameters:
numeral-Numeralto be converted- Returns:
doublerepresentation of the specified value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller than-Double.MAX_VALUEor greater thanDouble.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toBigDec
- Parameters:
numeral-Numeralto be converted- Returns:
BigDecimalrepresentation of the specified value- Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toSmallestType
- Parameters:
numeral-Numeralto be converted- Returns:
- a
Numeralbacked with the smallest type that can hold the specified Numeral's value. This method does not convert between integer and decimal types. - Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toInteger
- Parameters:
numeral-Numeralto be converted- Returns:
- a
Numeralbacked with the smallest integer type that can hold the specified Numeral's value, unless the Numeral is already an integer, in which case the specified Numeral is returned - Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toDecimal
- Parameters:
numeral-Numeralto be converted- Returns:
- a
Numeralbacked with the smallest decimal type that can hold the specified Numeral's value, unless the Numeral is already a decimal, in which case the specified Numeral is returned - Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toNumeral
- Parameters:
numeral-Numeralto be convertedtype- type for theNumeralto be converted to- Returns:
- a
Numeralbacked with the specified type - Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis outside the specified type's boundsNullPointerException- if the specified type isnullor if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if the specified type is notnullor if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toIntNumeral
- Parameters:
numeral-Numeralto be converted- Returns:
Numeralbacked by anintwith the specified Numeral's value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller thanInteger.MIN_VALUEor greater thanInteger.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toLongNumeral
- Parameters:
numeral-Numeralto be converted- Returns:
Numeralbacked by alongwith the specified Numeral's value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller thanLong.MIN_VALUEor greater thanLong.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toBigIntNumeral
- Parameters:
numeral-Numeralto be converted- Returns:
Numeralbacked by aBigIntegerwith the specified Numeral's value- Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toFloatNumeral
- Parameters:
numeral-Numeralto be converted- Returns:
Numeralbacked by afloatwith the specified Numeral's value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller than-Float.MAX_VALUEor greater thanFloat.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toDoubleNumeral
- Parameters:
numeral-Numeralto be converted- Returns:
Numeralbacked by adoublewith the specified Numeral's value- Throws:
ExtendedArithmeticException- if the value of the specifiedNumeralis smaller than-Double.MAX_VALUEor greater thanDouble.MAX_VALUENullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
toBigDecNumeral
- Parameters:
numeral-Numeralto be converted- Returns:
Numeralbacked by aBigDecimalwith the specified Numeral's value- Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-