Class Frequency

  • All Implemented Interfaces:
    java.lang.Comparable<Frequency>, RichComparable<Frequency>

    public final class Frequency
    extends java.lang.Object
    implements RichComparable<Frequency>
    Class representing frequency. This class is intended to be used for a value whose unit is Hz and its family (KHz, MHz, etc.).

    Note: this class is mainly intended to be used for lambda, which represents THz order. Long has enough space to represent over THz frequency as Hz, and the underlying value is long as Hz. This means this class can't represent sub-Hz accuracy.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Frequency add​(Frequency value)
      Returns a Frequency whose value is (this + value).
      double asGHz()
      Return the value this instance represents as GHz.
      long asHz()
      Return the value this instance represents as Hz.
      double asKHz()
      Return the value this instance represents as KHz.
      double asMHz()
      Return the value this instance represents as MHz.
      double asTHz()
      Return the value this instance represents as THz.
      int compareTo​(Frequency other)  
      boolean equals​(java.lang.Object obj)  
      Frequency floorDivision​(long value)
      Returns a Frequency whose value is Math.floorDiv(this, value).
      int hashCode()  
      Frequency multiply​(long value)
      Returns a Frequency whose value is (this * value).
      static Frequency ofGHz​(double value)
      Returns an instance representing the specified value in GHz.
      static Frequency ofGHz​(long value)
      Returns an instance representing the specified value in GHz.
      static Frequency ofHz​(long value)
      Returns an instance representing the specified value in Hz.
      static Frequency ofKHz​(double value)
      Returns an instance representing the specified value in KHz.
      static Frequency ofKHz​(long value)
      Returns an instance representing the specified value in KHz.
      static Frequency ofMHz​(double value)
      Returns an instance representing the specified value in MHz.
      static Frequency ofMHz​(long value)
      Returns an instance representing the specified value in MHz.
      static Frequency ofTHz​(double value)
      Returns an instance representing the specified value in THz.
      static Frequency ofTHz​(long value)
      Returns an instance representing the specified value in THz.
      Frequency subtract​(Frequency value)
      Returns a Frequency whose value is (this - value).
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • asHz

        public long asHz()
        Return the value this instance represents as Hz.
        Returns:
        frequency in Hz
      • asKHz

        public double asKHz()
        Return the value this instance represents as KHz.
        Returns:
        frequency in kHz
      • asMHz

        public double asMHz()
        Return the value this instance represents as MHz.
        Returns:
        frequency in MHz
      • asGHz

        public double asGHz()
        Return the value this instance represents as GHz.
        Returns:
        frequency in GHz
      • asTHz

        public double asTHz()
        Return the value this instance represents as THz.
        Returns:
        frequency in THz
      • ofHz

        public static Frequency ofHz​(long value)
        Returns an instance representing the specified value in Hz.
        Parameters:
        value - frequency in Hz
        Returns:
        instance representing the given frequency
      • ofKHz

        public static Frequency ofKHz​(long value)
        Returns an instance representing the specified value in KHz.
        Parameters:
        value - frequency in KHz
        Returns:
        instance representing the given frequency
      • ofKHz

        public static Frequency ofKHz​(double value)
        Returns an instance representing the specified value in KHz.
        Parameters:
        value - frequency in KHz
        Returns:
        instance representing the given frequency
      • ofMHz

        public static Frequency ofMHz​(long value)
        Returns an instance representing the specified value in MHz.
        Parameters:
        value - frequency in MHz
        Returns:
        instance representing the given frequency
      • ofMHz

        public static Frequency ofMHz​(double value)
        Returns an instance representing the specified value in MHz.
        Parameters:
        value - frequency in MHz
        Returns:
        instance representing the given frequency
      • ofGHz

        public static Frequency ofGHz​(long value)
        Returns an instance representing the specified value in GHz.
        Parameters:
        value - frequency in GHz
        Returns:
        instance representing the given frequency
      • ofGHz

        public static Frequency ofGHz​(double value)
        Returns an instance representing the specified value in GHz.
        Parameters:
        value - frequency in GHz
        Returns:
        instance representing the given frequency
      • ofTHz

        public static Frequency ofTHz​(long value)
        Returns an instance representing the specified value in THz.
        Parameters:
        value - frequency in THz
        Returns:
        instance representing the given frequency
      • ofTHz

        public static Frequency ofTHz​(double value)
        Returns an instance representing the specified value in THz.
        Parameters:
        value - frequency in THz
        Returns:
        instance representing the given frequency
      • add

        public Frequency add​(Frequency value)
        Returns a Frequency whose value is (this + value).
        Parameters:
        value - value to be added to this Frequency
        Returns:
        this + value
      • subtract

        public Frequency subtract​(Frequency value)
        Returns a Frequency whose value is (this - value).
        Parameters:
        value - value to be subtracted from this Frequency
        Returns:
        this - value
      • multiply

        public Frequency multiply​(long value)
        Returns a Frequency whose value is (this * value).
        Parameters:
        value - value to be multiplied by this Frequency
        Returns:
        this * value
      • floorDivision

        public Frequency floorDivision​(long value)
        Returns a Frequency whose value is Math.floorDiv(this, value).
        Parameters:
        value - value to be divided by this Frequency
        Returns:
        Math.floorDiv(this, value)
      • compareTo

        public int compareTo​(Frequency other)
        Specified by:
        compareTo in interface java.lang.Comparable<Frequency>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object