Class IntNumeral
java.lang.Object
me.datafox.dfxengine.math.numeral.IntNumeral
- All Implemented Interfaces:
Comparable<Numeral>,Numeral
Implementation of
Numeral backed with an int.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanConvert(NumeralType type) intCompares this numeral with the specified numeral for order.convert(NumeralType type) convertIfAllowed(NumeralType type) doublefloatprotected org.slf4j.LoggergetType()intintValue()longtoString()
-
Constructor Details
-
IntNumeral
public IntNumeral(int number) - Parameters:
number-intto be associated with this numeral
-
-
Method Details
-
getNumber
- Returns:
- the
Numberbacking this numeral
-
intValue
public int intValue() -
getLogger
protected org.slf4j.Logger getLogger()- Returns:
Loggerfor this numeral
-
getType
-
canConvert
- Specified by:
canConvertin interfaceNumeral- Parameters:
type- type to be checked for- Returns:
trueif this numeral can be converted to the specified type- Throws:
NullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happen
-
convert
- Specified by:
convertin interfaceNumeral- Parameters:
type- type for this numeral to be converted to- Returns:
- a numeral backed with the specified type
- Throws:
ExtendedArithmeticException- if the value of this numeral is outside the provided type's boundsNullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happen
-
convertIfAllowed
- Specified by:
convertIfAllowedin interfaceNumeral- Parameters:
type- type for this numeral to be converted to- Returns:
- a numeral backed with the specified type, unless the value of this numeral is outside the specified type's bounds, in which case this numeral is returned
- Throws:
NullPointerException- if the specified type isnullIllegalArgumentException- if the specified type is notnull, but it is not recognised as any of the elements ofNumeralType. This should never happen
-
toInteger
-
toDecimal
-
toSmallestType
- Specified by:
toSmallestTypein interfaceNumeral- Returns:
- a numeral backed with the smallest type that can hold this numeral's value. This method does not convert between integer and decimal types.
-
longValue
public long longValue()- Specified by:
longValuein interfaceNumeral- Returns:
- the value of this numeral as a
long - Throws:
ExtendedArithmeticException- if the value of this numeral is smaller thanLong.MIN_VALUEor greater thanLong.MAX_VALUE
-
bigIntValue
- Specified by:
bigIntValuein interfaceNumeral- Returns:
- the value of this numeral as a
BigInteger
-
floatValue
public float floatValue()- Specified by:
floatValuein interfaceNumeral- Returns:
- the value of this numeral as a
float - Throws:
ExtendedArithmeticException- if the value of this numeral is smaller than-Float.MAX_VALUEor greater thanFloat.MAX_VALUE
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein interfaceNumeral- Returns:
- the value of this numeral as a
double - Throws:
ExtendedArithmeticException- if the value of this numeral is smaller than-Double.MAX_VALUEor greater thanDouble.MAX_VALUE
-
bigDecValue
- Specified by:
bigDecValuein interfaceNumeral- Returns:
- the value of this numeral as a
BigDecimal
-
toString
-
compareTo
Compares this numeral with the specified numeral for order. The numerals are compared usingNumerals.compare(Numeral, Numeral). Returns a negative integer, zero, or a positive integer as this numeral is less than, equal to, or greater than the specified numeral.- Specified by:
compareToin interfaceComparable<Numeral>- Parameters:
other- the numeral to be compared- Returns:
- a negative integer, zero, or a positive integer as this numeral is less than, equal to, or greater than the specified numeral
- Throws:
NullPointerException- if theNumeralreturnsnullforNumeral.getType()IllegalArgumentException- if theNumeraldoes not returnnullforNumeral.getType(), but the value is not recognised as any of the values ofNumeralType. This should never happen
-