Class Rationnal

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

public class Rationnal extends Object implements Atom
Rationnal Number type is used to represent fractions e.g. 1/2
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Rationnal(int value)
    Constructor method for a whole number * @param value The integer value (e.g., 5 becomes 5/1)
    Rationnal(int numerator, int denominator)
    Constructor method * @param numerator The numerator
    Rationnal(org.apache.commons.numbers.fraction.Fraction value)
    Constructor method from an existing Fraction object * @param value The commons-numbers Fraction object
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accepts the specific AtomVisitor
    void
    accept is a method needed to implement the visitor design pattern
    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 atoms of the same concrete type The function supposes that both atoms are of the same concrete type
    boolean
     
    int
     
    int
     
    org.apache.commons.numbers.fraction.Fraction
    getter method to obtain the value contained in the object
    int
     
     

    Methods inherited from class Object

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

    • Rationnal

      public Rationnal(int numerator, int denominator)
      Constructor method * @param numerator The numerator
      Parameters:
      denominator - The denominator
    • Rationnal

      public Rationnal(int value)
      Constructor method for a whole number * @param value The integer value (e.g., 5 becomes 5/1)
    • Rationnal

      public Rationnal(org.apache.commons.numbers.fraction.Fraction value)
      Constructor method from an existing Fraction object * @param value The commons-numbers Fraction object
  • Method Details

    • getValue

      public org.apache.commons.numbers.fraction.Fraction getValue()
      getter method to obtain the value contained in the object
      Returns:
      The commons-numbers Fraction number contained in the object
    • apply

      public Atom apply(Operation o, Atom a)
      Description copied from interface: Atom
      Applies an operation 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:
      o - the operation to apply
      a - the other atom
      Returns:
      the result of the operation having the same type as a
      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 Rationnal 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
    • accept

      public void accept(AtomVisitor v)
      Description copied from interface: Atom
      accepts the specific AtomVisitor
      Specified by:
      accept in interface Atom
      Parameters:
      v - The Atomvisitor object being passed as a parameter
    • accept

      public void accept(Visitor v)
      Description copied from interface: Expression
      accept is a method needed to implement the visitor design pattern
      Specified by:
      accept in interface Expression
      Parameters:
      v - The visitor object being passed as a parameter
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getNumerator

      public int getNumerator()
    • getDenominator

      public int getDenominator()
    • toString

      public String toString()
      Overrides:
      toString in class Object