Class Real

java.lang.Object
calculator.atoms.Real
All Implemented Interfaces:
Atom, Expression

public class Real extends Object implements Atom
Real is a concrete class that represents arithmetic (Real) numbers, which are Atoms, a special kind of Expressions.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    static int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Real(double d)
    Constructor method for a double
    Real(int i)
    Constructor method
    Constructor method for a string
    Constructor method for a BigDecimal
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept method to implement the visitor design pattern to traverse arithmetic expressions.
    void
    accept method to implement the visitor design pattern to traverse arithmetic expressions.
    Applies an Binary between two atoms of the same concrete type The function supposes that both atoms are of the same concrete type
    Applies an operation on the atom
    applies an operation between two Reals
    boolean
    Two Real expressions are equal if the values they contain are equal
    getter method to obtain the value contained in the object
    int
    The method hashCode needs to be overridden it the equals method is overridden; otherwise there may be problems when you use your object in hashed collections such as HashMap, HashSet, LinkedHashSet.
    boolean
    Returns if the Real is representing -infinity
    boolean
    Returns if the Real is representing NaN
    boolean
    Returns if the Real is representing +infinity
    static Real
    Returns a Real representing -infinity
    static Real
    nan()
    Returns a NaN Real
    static Real
    Returns a Real representing +infinity
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • scale

      public static int scale
    • context

      public static MathContext context
  • Constructor Details

    • Real

      public Real(String s)
      Constructor method for a string
      Parameters:
      s - The string to be represented in the Real
    • Real

      public Real(BigDecimal d)
      Constructor method for a BigDecimal
      Parameters:
      d - the BigDecimal to be represented in the Real
    • Real

      public Real(double d)
      Constructor method for a double
      Parameters:
      d - The double to be represented in the Real
    • Real

      public Real(int i)
      Constructor method
      Parameters:
      i - The int value to be contained in the object
  • Method Details

    • getValue

      public BigDecimal getValue()
      getter method to obtain the value contained in the object
      Returns:
      The integer number contained in the object
    • nan

      public static Real nan()
      Returns a NaN Real
      Returns:
      A new Real number representing a NaN
    • plusInf

      public static Real plusInf()
      Returns a Real representing +infinity
      Returns:
      A new Real number representing +infinity
    • minusInf

      public static Real minusInf()
      Returns a Real representing -infinity
      Returns:
      A new Real number representing -infinity
    • isMinusInf

      public boolean isMinusInf()
      Returns if the Real is representing -infinity
      Returns:
      if the Real is representing -infinity
    • isPlusInf

      public boolean isPlusInf()
      Returns if the Real is representing +infinity
      Returns:
      if the Real is representing +infinity
    • isNan

      public boolean isNan()
      Returns if the Real is representing NaN
      Returns:
      if the Real is representing NaN
    • accept

      public void accept(AtomVisitor v)
      accept method to implement the visitor design pattern to traverse arithmetic expressions. Each real number will pass itself to the Atomvisitor object to get processed by the Atomvisitor.
      Specified by:
      accept in interface Atom
      Parameters:
      v - The Atomvisitor object
    • accept

      public void accept(Visitor v)
      accept method to implement the visitor design pattern to traverse arithmetic expressions. Each real number will pass itself to the visitor object to get processed by the visitor.
      Specified by:
      accept in interface Expression
      Parameters:
      v - The visitor object
    • equals

      public boolean equals(Object o)
      Two Real expressions are equal if the values they contain are equal
      Overrides:
      equals in class Object
      Parameters:
      o - The object to compare to
      Returns:
      A boolean representing the result of the equality test
    • hashCode

      public int hashCode()
      The method hashCode needs to be overridden it the equals method is overridden; otherwise there may be problems when you use your object in hashed collections such as HashMap, HashSet, LinkedHashSet.
      Overrides:
      hashCode in class Object
      Returns:
      The result of computing the hash.
    • apply

      public Real apply(Operation o, Atom a)
      applies an operation between two Reals
      Specified by:
      apply in interface Atom
      Parameters:
      o - the operation to apply
      a - the other Real
      Returns:
      The result of the application of o on a and this instance
      See Also:
    • apply

      public Atom apply(BinaryFunction f, Atom a)
      Description copied from interface: Atom
      Applies an Binary between two atoms of the same concrete type The function supposes that both atoms are of the same concrete type
      Specified by:
      apply in interface Atom
      Parameters:
      f - the binary function to with this atom as first parameter
      a - the other atom
      Returns:
      the result of the operation having the same type as a
      See Also:
    • apply

      public Real apply(UnaryFunction o)
      Description copied from interface: Atom
      Applies an operation on the atom
      Specified by:
      apply in interface Atom
      Parameters:
      o - the unary operation to apply
      Returns:
      the result of the operation
    • toString

      public String toString()
      Overrides:
      toString in class Object