com.alee.utils
Class TimeUtils

java.lang.Object
  extended by com.alee.utils.TimeUtils

public final class TimeUtils
extends java.lang.Object

This class provides a set of utilities for time measurement and comparison.

Author:
Mikle Garin

Constructor Summary
TimeUtils()
           
 
Method Summary
static void changeByDays(java.util.Calendar calendar, int days)
          Changes calendar date by the specified days amount.
static java.util.Date currentDate()
          Returns current system date.
static long currentNanoTime()
          Returns current system nano time.
static long currentTime()
          Returns current system time.
static void decreaseByDay(java.util.Calendar calendar)
          Decreases calendar date by one day.
static java.util.Date getEndOfDay(java.util.Date date)
          Returns end-of-day date.
static java.lang.Long getLastNanoTime()
          Returns either last pinned nanotime or last request nanotime.
static java.lang.Long getLastTime()
          Returns either last pinned time or last request time.
static long getPassedNanoTime()
          Returns nanotime passed since either last pin request or last nanotime request.
static long getPassedNanoTime(boolean total)
          Returns nanotime passed since either last pin request or last nanotime request if total is false.
static long getPassedTime()
          Returns time passed since either last pin request or last time request.
static long getPassedTime(boolean total)
          Returns time passed since either last pin request or last time request if total is false.
static java.lang.Long getPinnedNanoTime()
          Returns last pinned nanotime.
static java.lang.Long getPinnedTime()
          Returns last pinned time.
static java.util.Date getStartOfDay(java.util.Date date)
          Returns start-of-day date.
static void increaseByDay(java.util.Calendar calendar)
          Increases calendar date by one day.
static boolean isSameDay(java.util.Calendar calendar, java.util.Date date)
          Returns true if date contained in Calendar and specified date both represent the same day.
static boolean isSameDay(java.util.Calendar calendar, java.lang.Long date)
          Returns true if date contained in Calendar and specified time both represent the same day.
static boolean isSameDay(java.util.Date date1, java.util.Date date2)
          Returns true if both of the dates represent the same day.
static boolean isSameDay(java.lang.Long time1, java.lang.Long time2)
          Returns true if both of the time represent the same day.
static void pinNanoTime()
          Pins current system nanotime.
static void pinTime()
          Pins current system time.
static void resetNanoTime()
          Resets last pinned nanotime and last request nanotime.
static void resetTime()
          Resets last pinned time and last request time.
static void showPassedNanoTime()
          Writes nanotime passed since either last pin request or last nanotime request to log.
static void showPassedNanoTime(boolean total)
          Writes nanotime passed since either last pin request or last nanotime request if total is false to log.
static void showPassedNanoTime(boolean total, java.lang.String prefix)
          Writes nanotime passed since either last pin request or last nanotime request if total is false to log with specified prefix.
static void showPassedNanoTime(java.lang.String prefix)
          Writes nanotime passed since either last pin request or last nanotime request to log with specified prefix.
static void showPassedTime()
          Writes time passed since either last pin request or last time request to log.
static void showPassedTime(boolean total)
          Writes time passed since either last pin request or last time request if total is false to log.
static void showPassedTime(boolean total, java.lang.String prefix)
          Writes time passed since either last pin request or last time request if total is false to log with specified prefix.
static void showPassedTime(java.lang.String prefix)
          Writes time passed since either last pin request or last time request to log with specified prefix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeUtils

public TimeUtils()
Method Detail

getPinnedTime

public static java.lang.Long getPinnedTime()
Returns last pinned time.

Returns:
pinned time

getLastTime

public static java.lang.Long getLastTime()
Returns either last pinned time or last request time.

Returns:
last time

pinTime

public static void pinTime()
Pins current system time.


getPassedTime

public static long getPassedTime()
Returns time passed since either last pin request or last time request.

Returns:
passed time

getPassedTime

public static long getPassedTime(boolean total)
Returns time passed since either last pin request or last time request if total is false. Otherwise always returns time passed since last pin request.

Parameters:
total - should always return time passed since last pin request or not
Returns:
passed time

showPassedTime

public static void showPassedTime()
Writes time passed since either last pin request or last time request to log.


showPassedTime

public static void showPassedTime(java.lang.String prefix)
Writes time passed since either last pin request or last time request to log with specified prefix.

Parameters:
prefix - output string prefix

showPassedTime

public static void showPassedTime(boolean total)
Writes time passed since either last pin request or last time request if total is false to log. Otherwise always writes time passed since last pin request.

Parameters:
total - should always write time passed since last pin request or not

showPassedTime

public static void showPassedTime(boolean total,
                                  java.lang.String prefix)
Writes time passed since either last pin request or last time request if total is false to log with specified prefix. Otherwise always writes time passed since last pin request.

Parameters:
total - should always write time passed since last pin request or not
prefix - output string prefix

resetTime

public static void resetTime()
Resets last pinned time and last request time.


getPinnedNanoTime

public static java.lang.Long getPinnedNanoTime()
Returns last pinned nanotime.

Returns:
pinned nanotime

getLastNanoTime

public static java.lang.Long getLastNanoTime()
Returns either last pinned nanotime or last request nanotime.

Returns:
last nanotime

pinNanoTime

public static void pinNanoTime()
Pins current system nanotime.


getPassedNanoTime

public static long getPassedNanoTime()
Returns nanotime passed since either last pin request or last nanotime request.

Returns:
passed nanotime

getPassedNanoTime

public static long getPassedNanoTime(boolean total)
Returns nanotime passed since either last pin request or last nanotime request if total is false. Otherwise always returns nanotime passed since last pin request.

Parameters:
total - should always return time passed since last pin request or not
Returns:
passed nanotime

showPassedNanoTime

public static void showPassedNanoTime()
Writes nanotime passed since either last pin request or last nanotime request to log.


showPassedNanoTime

public static void showPassedNanoTime(java.lang.String prefix)
Writes nanotime passed since either last pin request or last nanotime request to log with specified prefix.

Parameters:
prefix - output string prefix

showPassedNanoTime

public static void showPassedNanoTime(boolean total)
Writes nanotime passed since either last pin request or last nanotime request if total is false to log. Otherwise always writes nanotime passed since last pin request.

Parameters:
total - should always write nanotime passed since last pin request or not

showPassedNanoTime

public static void showPassedNanoTime(boolean total,
                                      java.lang.String prefix)
Writes nanotime passed since either last pin request or last nanotime request if total is false to log with specified prefix. Otherwise always writes nanotime passed since last pin request.

Parameters:
total - should always write nanotime passed since last pin request or not
prefix - output string prefix

resetNanoTime

public static void resetNanoTime()
Resets last pinned nanotime and last request nanotime.


currentTime

public static long currentTime()
Returns current system time.

Returns:
system time

currentNanoTime

public static long currentNanoTime()
Returns current system nano time.

Returns:
system nanotime

currentDate

public static java.util.Date currentDate()
Returns current system date.

Returns:
system date

isSameDay

public static boolean isSameDay(java.util.Date date1,
                                java.util.Date date2)
Returns true if both of the dates represent the same day.

Parameters:
date1 - first date
date2 - second date
Returns:
day comparison result

isSameDay

public static boolean isSameDay(java.lang.Long time1,
                                java.lang.Long time2)
Returns true if both of the time represent the same day.

Parameters:
time1 - first time
time2 - second time
Returns:
day comparison result

isSameDay

public static boolean isSameDay(java.util.Calendar calendar,
                                java.util.Date date)
Returns true if date contained in Calendar and specified date both represent the same day.

Parameters:
calendar - calendar
date - date
Returns:
day comparison result

isSameDay

public static boolean isSameDay(java.util.Calendar calendar,
                                java.lang.Long date)
Returns true if date contained in Calendar and specified time both represent the same day.

Parameters:
calendar - calendar
date - date
Returns:
day comparison result

getStartOfDay

public static java.util.Date getStartOfDay(java.util.Date date)
Returns start-of-day date.

Parameters:
date - date to process
Returns:
start-of-day date

getEndOfDay

public static java.util.Date getEndOfDay(java.util.Date date)
Returns end-of-day date.

Parameters:
date - date to process
Returns:
end-of-day date

increaseByDay

public static void increaseByDay(java.util.Calendar calendar)
Increases calendar date by one day.

Parameters:
calendar - calendar that should be changed

decreaseByDay

public static void decreaseByDay(java.util.Calendar calendar)
Decreases calendar date by one day.

Parameters:
calendar - calendar that should be changed

changeByDays

public static void changeByDays(java.util.Calendar calendar,
                                int days)
Changes calendar date by the specified days amount.

Parameters:
calendar - calendar that should be changed
days - days amount