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 TypeMethodDescriptionlong
Returns the value of thedenominator
record component.double
final boolean
Indicates whether some other object is "equal to" this one.float
final int
hashCode()
Returns a hash code value for this object.long
Returns the value of thenumerator
record 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 aRational
record class.- Parameters:
numerator
- the value for thenumerator
record componentdenominator
- the value for thedenominator
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
- 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 thecompare
method from their corresponding wrapper classes. -
numerator
public long numerator()Returns the value of thenumerator
record component.- Returns:
- the value of the
numerator
record component
-
denominator
public long denominator()Returns the value of thedenominator
record component.- Returns:
- the value of the
denominator
record component
-