Class RepresentativeFractionImpl

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double doubleValue()
      Returns the scale in a form usable for computation.
      boolean equals​(Object object)
      Compares this object with the specified value for equality.
      float floatValue()
      Returns the scale as a float type.
      static RepresentativeFraction fromScale​(double scale)
      Creates a representative fraction from a scale as a double value.
      long getDenominator()
      Returns the number below the line in a vulgar fraction.
      int hashCode()
      Returns a hash value for this representative fraction.
      int intValue()
      Returns the scale as an integer.
      long longValue()
      Returns the scale as an integer.
      void setDenominator​(long denominator)
      Sets the denominator value.
      • Methods inherited from class Number

        byteValue, shortValue
      • Methods inherited from class Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RepresentativeFractionImpl

        public RepresentativeFractionImpl()
        Default empty constructor.
      • RepresentativeFractionImpl

        public RepresentativeFractionImpl​(long denominator)
        Creates a new representative fraction from the specified denominator.
        Parameters:
        denominator - The denominator.
    • Method Detail

      • fromScale

        public static RepresentativeFraction fromScale​(double scale)
                                                throws IllegalArgumentException
        Creates a representative fraction from a scale as a double value. The denominator will be set to 1/scale.
        Parameters:
        scale - The scale as a number between 0 and 1.
        Returns:
        The representative fraction created from the given scale.
        Throws:
        IllegalArgumentException - if the condition abs(scale) <= 1 is not meet.
      • doubleValue

        public double doubleValue()
        Returns the scale in a form usable for computation.
        Specified by:
        doubleValue in interface RepresentativeFraction
        Specified by:
        doubleValue in class Number
        Returns:
        1.0 / denominator
      • floatValue

        public float floatValue()
        Returns the scale as a float type.
        Specified by:
        floatValue in class Number
      • longValue

        public long longValue()
                       throws ArithmeticException
        Returns the scale as an integer. This method returns 0, 1 or throws an exception as specified in intValue().
        Specified by:
        longValue in class Number
        Throws:
        ArithmeticException - if the denominator is 0.
      • intValue

        public int intValue()
                     throws ArithmeticException
        Returns the scale as an integer. If the denominator is 0, then this method throws an ArithmeticException since infinities can not be represented by an integer. Otherwise if the denominator is 1, then this method returns 1. Otherwise returns 0 0 since the scale is a fraction between 0 and 1, and such value can not be represented as an integer.
        Specified by:
        intValue in class Number
        Throws:
        ArithmeticException - if the denominator is 0.
      • getDenominator

        public long getDenominator()
        Returns the number below the line in a vulgar fraction.
        Specified by:
        getDenominator in interface RepresentativeFraction
        Returns:
        The denominator.
      • setDenominator

        public void setDenominator​(long denominator)
        Sets the denominator value.
        Parameters:
        denominator - The new denominator value.
      • equals

        public boolean equals​(Object object)
        Compares this object with the specified value for equality.
        Specified by:
        equals in interface RepresentativeFraction
        Overrides:
        equals in class Object
        Parameters:
        object - The object to compare with.
        Returns:
        true if both objects are equal.
      • hashCode

        public int hashCode()
        Returns a hash value for this representative fraction.
        Specified by:
        hashCode in interface RepresentativeFraction
        Overrides:
        hashCode in class Object
        Returns:
        A hash code value for this representative fraction.