Class AtomCaster

java.lang.Object
calculator.atoms.visitor.AtomVisitor
calculator.atoms.visitor.AtomCaster

public class AtomCaster extends AtomVisitor
AtomCaster is an AtomVisitor whose goal is to cast the visited atom to the specified type and throws errors if this cast is impossible e.g a complex to an Integer
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an AtomCaster to cast to the specified type
  • Method Summary

    Modifier and Type
    Method
    Description
    returns the result of the cast of the visited to the specified type
    void
    Visiting a Complex Atom to cast it to the specified type of the visitor
    void
    Visiting a Integer Atom to cast it to the specified type of the visitor
    void
    Visiting a Rationnal Atom to cast it to the specified type of the visitor
    void
    Visiting a Real Atom to cast it to the specified type of the visitor

    Methods inherited from class Object

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

    • AtomCaster

      public AtomCaster(AtomType type)
      Constructs an AtomCaster to cast to the specified type
      Parameters:
      type - The type to Cast the visited Atom to
  • Method Details

    • getResult

      public Atom getResult()
      returns the result of the cast of the visited to the specified type
      Returns:
      the Result of the cast from the visited Atom to the specified type
    • visit

      public void visit(Real r)
      Visiting a Real Atom to cast it to the specified type of the visitor
      Specified by:
      visit in class AtomVisitor
      Parameters:
      r - The visited Real to be cast
      Throws:
      IllegalAtomCast - in case of an impossible cast
    • visit

      public void visit(Complex c)
      Visiting a Complex Atom to cast it to the specified type of the visitor
      Specified by:
      visit in class AtomVisitor
      Parameters:
      c - The visited Complex to be cast
      Throws:
      IllegalAtomCast - in case of an impossible cast
    • visit

      public void visit(Rationnal q)
      Visiting a Rationnal Atom to cast it to the specified type of the visitor
      Specified by:
      visit in class AtomVisitor
      Parameters:
      q - The visited Rationnal to be cast
      Throws:
      IllegalAtomCast - in case of an impossible cast
    • visit

      public void visit(IntegerAtom i)
      Visiting a Integer Atom to cast it to the specified type of the visitor
      Specified by:
      visit in class AtomVisitor
      Parameters:
      i - The visited IntegerAtom to be cast
      Throws:
      IllegalAtomCast - in case of an impossible cast