Package me.datafox.dfxengine.math.utils
Class Numerals
java.lang.Object
me.datafox.dfxengine.math.utils.Numerals
Various operations for
Numerals.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intstatic NumeralTypegetSignificantType(NumeralType... types) Returns the most significantNumeralType.static NumeralTypegetSignificantType(NumeralType type1, NumeralType type2) static booleanstatic booleanstatic booleanstatic DoubleNumeralof(double d) static FloatNumeralof(float f) static IntNumeralof(int i) static LongNumeralof(long l) static NumeralIf theNumberis not an instance ofInteger,Long,BigInteger,Float,DoubleorBigDecimal, this method attempts to parse the number usingObject.toString().static NumeralIf the specifiedStringrepresents an integer, aBigIntNumeralis returned.static BigDecNumeralof(BigDecimal bd) static BigIntNumeralof(BigInteger bi)
-
Constructor Details
-
Numerals
public Numerals()
-
-
Method Details
-
of
- Parameters:
i-intvalue- Returns:
IntNumeralrepresenting specified value
-
of
- Parameters:
l-longvalue- Returns:
LongNumeralrepresenting specified value
-
of
- Parameters:
bi-BigIntegervalue- Returns:
BigIntNumeralrepresenting specified value
-
of
- Parameters:
f-floatvalue- Returns:
FloatNumeralrepresenting specified value
-
of
- Parameters:
d-doublevalue- Returns:
DoubleNumeralrepresenting specified value
-
of
- Parameters:
bd-BigDecimalvalue- Returns:
BigDecNumeralrepresenting specified value
-
of
If the specifiedStringrepresents an integer, aBigIntNumeralis returned. Otherwise, aBigDecNumeralis returned. A string is considered to represent an integer if it does not contain any of the characters.,eorE.- Parameters:
str-Stringrepresentation of a numeric value- Returns:
Numeralrepresenting specified value- Throws:
NumberFormatException- if str is not a valid number representation
-
of
If theNumberis not an instance ofInteger,Long,BigInteger,Float,DoubleorBigDecimal, this method attempts to parse the number usingObject.toString().- Parameters:
number-Numbervalue- Returns:
Numeralrepresenting the specified value- Throws:
NumberFormatException- If theNumberis not recognised and parsing its string representation fails
-
isZero
- Parameters:
numeral-Numeralto be checked- Returns:
trueif the specified value represents the number zero- 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
-
isOne
- Parameters:
numeral-Numeralto be checked- Returns:
trueif the specified value represents the number one- 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
-
isEven
- Parameters:
numeral-Numeralto be checked- Returns:
trueif theNumeralrepresents an even number. For decimal Numerals, the number must not have a decimal part fortrueto be 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
-
compare
- Parameters:
numeral- firstNumeralto compareother- secondNumeralto compare- Returns:
- 0 if the
Numeralvalues represent the same number, 1 if the first Numeral represents a larger value than the second Numeral, and -1 if the first Numeral represents a smaller value than the second Numeral. - Throws:
NullPointerException- if any of theNumeralsreturnnullforNumeral.getType()IllegalArgumentException- if any of theNumeralsdo not returnnullforNumeral.getType(), but the value is not recognised as any of the elements ofNumeralType. This should never happen
-
getSignificantType
- Parameters:
type1- firstNumeralTypetype2- secondNumeralType- Returns:
- the most significant type of specified values
- Throws:
NullPointerException- if any of the types arenull- See Also:
-
getSignificantType
Returns the most significant
NumeralType. The significance of a type is determined by how large numerical values it can represent. If any of the specified types is adecimal type, the return value of this method is also a decimal type. If any of the specified types isnull, the return value is alsonull.nullcheck takes precedence over all other checks.Therefore, if any of the specified types is
BIG_DEC, BIG_DEC is also returned. BIG_DEC is also returned if any of the specified types isBIG_INTand another is a decimal type. In all other cases the specified type with the highestsignificancewill be returned.- Parameters:
types- types to be checked- Returns:
- the most significant type
- Throws:
NullPointerException- if any of the types arenull
-