Class IntegerAtom

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

public class IntegerAtom extends Object implements Atom
IntegerAtom is a concrete class that represents arithmetic (integer) numbers, which are Atoms, a special kind of Expressions, just like operations are.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    IntegerAtom(int i)
    Constructor method
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept method to implement the visitor design pattern to traverse Atoms.
    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 a unary operation to the IntegerAtom
    applies an operation between two IntegerAtom
    boolean
    Two Integers Atoms are equal if the values they contain are equal
    int
    returns the value of the integer
    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.
     

    Methods inherited from class Object

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

    • IntegerAtom

      public IntegerAtom(int i)
      Constructor method
      Parameters:
      i - The integer value
  • Method Details

    • accept

      public void accept(AtomVisitor v)
      accept method to implement the visitor design pattern to traverse Atoms. Each Integer 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 Integer 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 Integers Atoms 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 Atom apply(Operation o, Atom a)
      applies an operation between two IntegerAtom
      Specified by:
      apply in interface Atom
      Parameters:
      o - the operation to apply
      a - the other IntegerAtom
      Returns:
      The result of the application of o on a and this instance
      See Also:
    • apply

      public IntegerAtom apply(UnaryFunction o)
      applies a unary operation to the IntegerAtom
      Specified by:
      apply in interface Atom
      Parameters:
      o - the operation to apply
      Returns:
      The result of the application
    • 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:
    • getValue

      public int getValue()
      returns the value of the integer
      Returns:
      the value of the integer
    • toString

      public String toString()
      Overrides:
      toString in class Object