Class ExactIntegerField
java.lang.Object
com.singularsys.extensions.field.AbstractComparativeField
com.singularsys.extensions.field.implementations.GenericField<Integer>
com.singularsys.extensions.field.implementations.GenericPowerField<Integer>
com.singularsys.extensions.field.implementations.ExactIntegerField
- All Implemented Interfaces:
FieldI,IntegerConvertor,Serializable
An integer field where results are always integers and Exceptions are thrown
on error. The actual exception thrown is an ArithmeticException wrapped in
EvaluationExceptions. Where possible it uses the
Math.addExact(int,int) etc. methods.- Author:
- Richard Morris
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.extensions.field.implementations.GenericPowerField
one, zero -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds two elements of type E.Convert the input to type E.Compare two objects of the same type.Attempt to convert argument from an integerIf possible convert the argument to an Integer to enable integral powers.Divides two elements of type E.getOne()Get the multiplicative identity for this field.getZero()Get the additive identity for this fieldModulus of two elements of type E.Multiplies two elements of type E.Negates an elements of type E.If r is integral (convertToInt returns non-null) call powI otherwise call powNIprotected IntegerCalled when the power is not an integerSubtracts two elements of type E.Methods inherited from class com.singularsys.extensions.field.implementations.GenericField
add, and, cmp, convertToInt, div, mod, mul, neg, not, or, pow, sub
-
Constructor Details
-
ExactIntegerField
public ExactIntegerField(boolean checkDivide) Constructor- Parameters:
checkDivide- whether to throw exception is division is not integral
-
-
Method Details
-
cast
Description copied from class:GenericFieldConvert the input to type E.- Specified by:
castin classGenericField<Integer>- Parameters:
l-- Returns:
- l cast to type E if possible or null if casting is not possible
-
addG
Description copied from class:GenericFieldAdds two elements of type E.- Specified by:
addGin classGenericField<Integer>- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the sum
- Throws:
EvaluationException- on error
-
subG
Description copied from class:GenericFieldSubtracts two elements of type E.- Specified by:
subGin classGenericField<Integer>- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the difference
- Throws:
EvaluationException- on error
-
negG
Description copied from class:GenericFieldNegates an elements of type E.- Specified by:
negGin classGenericField<Integer>- Parameters:
l- the argument- Returns:
- the negation
- Throws:
EvaluationException- on error
-
mulG
Description copied from class:GenericFieldMultiplies two elements of type E.- Specified by:
mulGin classGenericField<Integer>- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the product
- Throws:
EvaluationException- on error
-
divG
Description copied from class:GenericFieldDivides two elements of type E.- Specified by:
divGin classGenericField<Integer>- Parameters:
l- numeratorr- denominator- Returns:
- the division
- Throws:
EvaluationException- on error
-
modG
Description copied from class:GenericFieldModulus of two elements of type E.- Specified by:
modGin classGenericField<Integer>- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the modulus
- Throws:
EvaluationException- on error
-
powG
Description copied from class:GenericPowerFieldIf r is integral (convertToInt returns non-null) call powI otherwise call powNI- Overrides:
powGin classGenericPowerField<Integer>- Parameters:
l- lhs argumentr- rhs argument- Returns:
- the power
- Throws:
EvaluationException- on error
-
cmpG
Description copied from class:GenericFieldCompare two objects of the same type.- Specified by:
cmpGin classGenericField<Integer>- Parameters:
l- left argumentr- right argument- Returns:
- -1, 0, 1 or null
-
powNonInt
Description copied from class:GenericPowerFieldCalled when the power is not an integer- Specified by:
powNonIntin classGenericPowerField<Integer>- Parameters:
l-r-- Returns:
- Throws:
EvaluationException
-
powI
- Overrides:
powIin classGenericPowerField<Integer>- Throws:
EvaluationException
-
getOne
Description copied from interface:FieldIGet the multiplicative identity for this field.- Specified by:
getOnein interfaceFieldI- Specified by:
getOnein classGenericField<Integer>- Returns:
- object representing one or null if undefined for this field
-
getZero
Description copied from interface:FieldIGet the additive identity for this field- Specified by:
getZeroin interfaceFieldI- Specified by:
getZeroin classGenericField<Integer>- Returns:
- object representing zero or null if undefined for this field
-
convertToIntE
Description copied from class:GenericFieldIf possible convert the argument to an Integer to enable integral powers. If the argument cannot be converted null should be returned and thepowG(E,E)method will be called.- Specified by:
convertToIntEin classGenericField<Integer>- Parameters:
l- argument to convert.- Returns:
- an integer or null if argument cannot be converted
-
convertFromInt
Description copied from interface:IntegerConvertorAttempt to convert argument from an integer- Specified by:
convertFromIntin interfaceIntegerConvertor- Specified by:
convertFromIntin classGenericField<Integer>- Parameters:
l- value to convert- Returns:
- corresponding value in this field or null if it cannot be converted
-