Class MathUtils


  • public class MathUtils
    extends java.lang.Object
    Provides misc math functions that don't come standard.
    • Constructor Summary

      Constructors 
      Constructor Description
      MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long elapsedMicroSec​(long startNanoTime)
      Microseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
      static long elapsedMSec​(long startNanoTime)
      Milliseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
      static long elapsedNanos​(long startNanoTime)
      Nanoseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
      static int findNextPositivePowerOfTwo​(int value)  
      static long nowInNano()
      Current time from some arbitrary time base in the past, counting in nanoseconds, and not affected by settimeofday or similar system clock changes.
      static int signSafeMod​(long dividend, int divisor)  
      • Methods inherited from class java.lang.Object

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

      • MathUtils

        public MathUtils()
    • Method Detail

      • signSafeMod

        public static int signSafeMod​(long dividend,
                                      int divisor)
      • findNextPositivePowerOfTwo

        public static int findNextPositivePowerOfTwo​(int value)
      • nowInNano

        public static long nowInNano()
        Current time from some arbitrary time base in the past, counting in nanoseconds, and not affected by settimeofday or similar system clock changes. This is appropriate to use when computing how much longer to wait for an interval to expire.

        NOTE: only use it for measuring. http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#nanoTime%28%29

        Returns:
        current time in nanoseconds.
      • elapsedMSec

        public static long elapsedMSec​(long startNanoTime)
        Milliseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
        Parameters:
        startNanoTime - the start of the interval that we are measuring
        Returns:
        elapsed time in milliseconds.
      • elapsedMicroSec

        public static long elapsedMicroSec​(long startNanoTime)
        Microseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
        Parameters:
        startNanoTime - the start of the interval that we are measuring
        Returns:
        elapsed time in microseconds.
      • elapsedNanos

        public static long elapsedNanos​(long startNanoTime)
        Nanoseconds elapsed since the time specified, the input is nanoTime the only conversion happens when computing the elapsed time.
        Parameters:
        startNanoTime - the start of the interval that we are measuring
        Returns:
        elapsed time in nanoseconds.