Record Class Rational

java.lang.Object
java.lang.Record
is.galia.util.Rational

public record Rational(long numerator, long denominator) extends Record
Rational number, i.e. fraction.
  • Constructor Details

    • Rational

      public Rational(long numerator, long denominator)
      Creates an instance of a Rational record class.
      Parameters:
      numerator - the value for the numerator record component
      denominator - the value for the denominator record component
    • Rational

      public Rational(short numerator, short denominator)
    • Rational

      public Rational(int numerator, int denominator)
  • Method Details

    • doubleValue

      public double doubleValue()
    • floatValue

      public float floatValue()
    • reduced

      public Rational reduced()
      Returns:
      New instance reduced to lowest terms, or the same instance if it is already reduced to lowest terms.
    • toMap

      public Map<String,Long> toMap()
      Returns:
      Map with numerator and denominator keys.
    • 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 class Record
      Returns:
      a string representation of this object
    • 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
    • equals

      public final boolean equals(Object o)
      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:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • numerator

      public long numerator()
      Returns the value of the numerator record component.
      Returns:
      the value of the numerator record component
    • denominator

      public long denominator()
      Returns the value of the denominator record component.
      Returns:
      the value of the denominator record component