Record Class Num

All Implemented Interfaces:
Expr, Value

record Num(double x) extends Record implements Value
Our internal representation of a number in the OG0 language.
  • Field Summary

    Fields inherited from interface Expr

    PUNCTUATION
  • Constructor Summary

    Constructors
    Constructor
    Description
    Num(double x)
    Creates an instance of a Num record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) double
    Return the Java double this Value represents (for use by other primitives in our language.)
    boolean
    equals(Object that)
    Indicates whether some other object is "equal to" this one.
    Evaluate a given Expr.
    final int
    Returns a hash code value for this object.
    static Num
    parse(Scanner s, String punctuation)
    Returns a string representation of this record class.
    double
    x()
    Returns the value of the x record component.

    Methods inherited from class java.lang.Object

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

    • Num

      Num(double x)
      Creates an instance of a Num record class.
      Parameters:
      x - the value for the x record component
  • Method Details

    • eval

      public Value eval()
      Description copied from interface: Expr
      Evaluate a given Expr.
      Specified by:
      eval in interface Expr
      Specified by:
      eval in interface Value
      Returns:
      the Value this Expr evaluates to. (In OG0, all values are numbers (doubles), but in OG3 that will change, which is why we have pre-emptively made the return type 'Value'.)
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in interface Expr
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • parse

      public static Num parse(Scanner s, String punctuation)
    • doubleValue

      double doubleValue()
      Return the Java double this Value represents (for use by other primitives in our language.)
      Returns:
      the Java double this Value represents.
    • equals

      public boolean equals(Object that)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      that - the object with which to compare
      Returns:
      true if this object is the same as the that argument; false otherwise.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • x

      public double x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component