Record Class Rational
java.lang.Object
java.lang.Record
is.galia.util.Rational
Rational number, i.e. fraction.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the value of thedenominatorrecord component.doublefinal booleanIndicates whether some other object is "equal to" this one.floatfinal inthashCode()Returns a hash code value for this object.longReturns the value of thenumeratorrecord component.reduced()toMap()toString()Returns a string representation of this record class.
-
Constructor Details
-
Rational
public Rational(long numerator, long denominator) Creates an instance of aRationalrecord class.- Parameters:
numerator- the value for thenumeratorrecord componentdenominator- the value for thedenominatorrecord 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
- Returns:
- New instance reduced to lowest terms, or the same instance if it is already reduced to lowest terms.
-
toMap
-
toString
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
numerator
public long numerator()Returns the value of thenumeratorrecord component.- Returns:
- the value of the
numeratorrecord component
-
denominator
public long denominator()Returns the value of thedenominatorrecord component.- Returns:
- the value of the
denominatorrecord component
-