Class BtrpNumber

All Implemented Interfaces:
BtrpOperand, Copyable<BtrpOperand>

public class BtrpNumber
extends DefaultBtrpOperand
Denotes an number operand. The value may an integer or a real, either positive or negative. An integer can be expressed in base 10, 8 (octal) or 16 (hexadecimal) while a real is necessarily expressed in base 10.
Author:
Fabien Hermenier
  • Field Details

  • Constructor Details

    • BtrpNumber

      public BtrpNumber​(int v, BtrpNumber.Base b)
      Make a new integer.
      Parameters:
      v - the current value
      b - the base used when printing the value
    • BtrpNumber

      public BtrpNumber​(double d)
      Make a float number. The number will be represented in base 10.
      Parameters:
      d - the value.
  • Method Details

    • type

      public BtrpOperand.Type type()
      Description copied from interface: BtrpOperand
      Get the type of the operand.
      Returns:
      BtrpOperand.Type.NUMBER
    • getBase

      public BtrpNumber.Base getBase()
      Get the current base for the number
      Returns:
      the base
    • power

      public BtrpNumber power​(BtrpOperand nb)
      Description copied from interface: BtrpOperand
      Computes the power of this operand.
      Specified by:
      power in interface BtrpOperand
      Overrides:
      power in class DefaultBtrpOperand
      Parameters:
      nb - the other value. Must be a number
      Returns:
      an integer number if both operands are integer. A real number otherwise
    • plus

      public BtrpNumber plus​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Computes the addition of this operand with another one.
      Specified by:
      plus in interface BtrpOperand
      Overrides:
      plus in class DefaultBtrpOperand
      Parameters:
      other - the other value. Must be a number
      Returns:
      the result of the addition
    • minus

      public BtrpNumber minus​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Computes the difference between this operand and another one.
      Specified by:
      minus in interface BtrpOperand
      Overrides:
      minus in class DefaultBtrpOperand
      Parameters:
      other - the other value. Must be a number
      Returns:
      the result of the difference
    • negate

      public BtrpNumber negate()
      Description copied from interface: BtrpOperand
      Computes the negation of this operand.
      Specified by:
      negate in interface BtrpOperand
      Overrides:
      negate in class DefaultBtrpOperand
      Returns:
      the result of the negation
    • times

      public BtrpNumber times​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Multiply this operand by another one
      Specified by:
      times in interface BtrpOperand
      Overrides:
      times in class DefaultBtrpOperand
      Parameters:
      other - the other value. Must be a number
      Returns:
      the result of the negation
    • div

      public BtrpNumber div​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Divides this operand by another one.
      Specified by:
      div in interface BtrpOperand
      Overrides:
      div in class DefaultBtrpOperand
      Parameters:
      other - the other value. Must be a number
      Returns:
      the result of the division
    • remainder

      public BtrpNumber remainder​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Computes the remainder of this operand division by another one
      Specified by:
      remainder in interface BtrpOperand
      Overrides:
      remainder in class DefaultBtrpOperand
      Parameters:
      other - the other value. Must be a number
      Returns:
      the remainder of the division
    • equals

      public boolean equals​(Object o)
      Check the equality of two elements. Both are equals if they are an instance of a same class and if they contains the same element.
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Textual representation of the integer. The base is considered.
      Overrides:
      toString in class Object
      Returns:
      a String
    • degree

      public int degree()
      Description copied from interface: BtrpOperand
      Get the degree of the operand. A degree of 0 indicates a single value. A degree of 1 indicates a set of single value. A degree of 2 indicate a set of set of values. Basically. An operand with a degree n is a set of elements with all having the degree n - 1
      Returns:
      0
    • getIntValue

      public int getIntValue()
      The integer value of this operand.
      Returns:
      the integer given at instantiation if the number is an integer. 0 otherwise
    • getDoubleValue

      public double getDoubleValue()
      The real value of this operand.
      Returns:
      the real given at instantiation if the number is a real. 0 otherwise
    • eq

      public BtrpNumber eq​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Check if this operand is equals to another one.
      Specified by:
      eq in interface BtrpOperand
      Overrides:
      eq in class DefaultBtrpOperand
      Parameters:
      other - the operand to compare to
      Returns:
      TRUE if both operand are equals, FALSE otherwise
    • geq

      public BtrpNumber geq​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Check if this operand is greater or equals to another one.
      Specified by:
      geq in interface BtrpOperand
      Overrides:
      geq in class DefaultBtrpOperand
      Parameters:
      other - the operand to compare to
      Returns:
      TRUE if this operand is greater or equals, FALSE otherwise
    • gt

      public BtrpNumber gt​(BtrpOperand other)
      Description copied from interface: BtrpOperand
      Check if this operand is strictly greater than another one.
      Specified by:
      gt in interface BtrpOperand
      Overrides:
      gt in class DefaultBtrpOperand
      Parameters:
      other - the operand to compare to
      Returns:
      TRUE if this operand is strictly greater, FALSE otherwise
    • not

      public BtrpNumber not()
      Description copied from interface: BtrpOperand
      Compute the opposite of the operand.
      Specified by:
      not in interface BtrpOperand
      Overrides:
      not in class DefaultBtrpOperand
      Returns:
      the opposite operand
    • copy

      public BtrpNumber copy()
      Description copied from interface: Copyable
      Make a deep copy of the object.
      Returns:
      a deep copy
    • isInteger

      public boolean isInteger()
      Indicates whether or not the number is an integer.
      Returns:
      true if the number is an integer.