Class BigDecimalField

  • All Implemented Interfaces:
    FieldI, IntegerConvertor, java.io.Serializable

    public class BigDecimalField
    extends GenericField<java.math.BigDecimal>
    Implementation of field methods using BigDecimals
    Author:
    Richard Morris
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      BigDecimalField​(java.math.MathContext mc)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.math.BigDecimal addG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Adds two elements of type E.
      java.math.BigDecimal cast​(java.lang.Object l)
      Convert the input to type E.
      java.lang.Integer cmpG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Compare two objects of the same type.
      java.math.BigDecimal convertFromInt​(java.lang.Integer l)
      Attempt to convert argument from an integer
      java.lang.Integer convertToIntE​(java.math.BigDecimal l)
      If possible convert the argument to an Integer to enable integral powers.
      java.math.BigDecimal divG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Divides two elements of type E.
      java.math.BigDecimal getOne()
      Get the multiplicative identity for this field.
      java.math.BigDecimal getZero()
      Get the additive identity for this field
      java.math.BigDecimal modG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Modulus of two elements of type E.
      java.math.BigDecimal mulG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Multiplies two elements of type E.
      java.math.BigDecimal negG​(java.math.BigDecimal l)
      Negates an elements of type E.
      java.math.BigDecimal powG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Only integral values are allowed.
      java.math.BigDecimal subG​(java.math.BigDecimal l, java.math.BigDecimal r)
      Subtracts two elements of type E.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BigDecimalField

        public BigDecimalField​(java.math.MathContext mc)
        Parameters:
        mc -
    • Method Detail

      • cast

        public java.math.BigDecimal cast​(java.lang.Object l)
        Description copied from class: GenericField
        Convert the input to type E.
        Specified by:
        cast in class GenericField<java.math.BigDecimal>
        Returns:
        l if l is a BigDecimal, null otherwise
      • addG

        public java.math.BigDecimal addG​(java.math.BigDecimal l,
                                         java.math.BigDecimal r)
                                  throws EvaluationException
        Description copied from class: GenericField
        Adds two elements of type E.
        Specified by:
        addG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - lhs argument
        r - rhs argument
        Returns:
        the sum
        Throws:
        EvaluationException - on error
      • subG

        public java.math.BigDecimal subG​(java.math.BigDecimal l,
                                         java.math.BigDecimal r)
                                  throws EvaluationException
        Description copied from class: GenericField
        Subtracts two elements of type E.
        Specified by:
        subG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - lhs argument
        r - rhs argument
        Returns:
        the difference
        Throws:
        EvaluationException - on error
      • mulG

        public java.math.BigDecimal mulG​(java.math.BigDecimal l,
                                         java.math.BigDecimal r)
                                  throws EvaluationException
        Description copied from class: GenericField
        Multiplies two elements of type E.
        Specified by:
        mulG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - lhs argument
        r - rhs argument
        Returns:
        the product
        Throws:
        EvaluationException - on error
      • divG

        public java.math.BigDecimal divG​(java.math.BigDecimal l,
                                         java.math.BigDecimal r)
                                  throws EvaluationException
        Description copied from class: GenericField
        Divides two elements of type E.
        Specified by:
        divG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - numerator
        r - denominator
        Returns:
        the division
        Throws:
        EvaluationException - on error
      • modG

        public java.math.BigDecimal modG​(java.math.BigDecimal l,
                                         java.math.BigDecimal r)
                                  throws EvaluationException
        Description copied from class: GenericField
        Modulus of two elements of type E.
        Specified by:
        modG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - lhs argument
        r - rhs argument
        Returns:
        the modulus
        Throws:
        EvaluationException - on error
      • powG

        public java.math.BigDecimal powG​(java.math.BigDecimal l,
                                         java.math.BigDecimal r)
                                  throws EvaluationException
        Only integral values are allowed.
        Specified by:
        powG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - lhs argument
        r - rhs argument
        Returns:
        the power
        Throws:
        EvaluationException - for non integral values.
      • cmpG

        public java.lang.Integer cmpG​(java.math.BigDecimal l,
                                      java.math.BigDecimal r)
                               throws EvaluationException
        Description copied from class: GenericField
        Compare two objects of the same type.
        Specified by:
        cmpG in class GenericField<java.math.BigDecimal>
        Parameters:
        l - left argument
        r - right argument
        Returns:
        -1, 0, 1 or null
        Throws:
        EvaluationException
      • getOne

        public java.math.BigDecimal getOne()
        Description copied from interface: FieldI
        Get the multiplicative identity for this field.
        Specified by:
        getOne in interface FieldI
        Specified by:
        getOne in class GenericField<java.math.BigDecimal>
        Returns:
        object representing one or null if undefined for this field
      • getZero

        public java.math.BigDecimal getZero()
        Description copied from interface: FieldI
        Get the additive identity for this field
        Specified by:
        getZero in interface FieldI
        Specified by:
        getZero in class GenericField<java.math.BigDecimal>
        Returns:
        object representing zero or null if undefined for this field
      • convertToIntE

        public java.lang.Integer convertToIntE​(java.math.BigDecimal l)
                                        throws EvaluationException
        Description copied from class: GenericField
        If possible convert the argument to an Integer to enable integral powers. If the argument cannot be converted null should be returned and the powG(E,E) method will be called.
        Specified by:
        convertToIntE in class GenericField<java.math.BigDecimal>
        Parameters:
        l - argument to convert.
        Returns:
        an integer or null if argument cannot be converted
        Throws:
        EvaluationException