Class Util


  • public final class Util
    extends Object
    Provides general purpose utilites.
    • Field Detail

      • MAX_DATE

        public static Date MAX_DATE
        The maximum date possible.
    • Method Detail

      • isSameDay

        public static boolean isSameDay​(Date date1,
                                        Date date2)

        Checks if two dates are on the same day ignoring time.

        Parameters:
        date1 - the first date, not altered, not null
        date2 - the second date, not altered, not null
        Returns:
        true if they represent the same day
        Throws:
        IllegalArgumentException - if either date is null
      • isSameDay

        public static boolean isSameDay​(Calendar cal1,
                                        Calendar cal2)

        Checks if two calendars represent the same day ignoring time.

        Parameters:
        cal1 - the first calendar, not altered, not null
        cal2 - the second calendar, not altered, not null
        Returns:
        true if they represent the same day
        Throws:
        IllegalArgumentException - if either calendar is null
      • isToday

        public static boolean isToday​(Date date)

        Checks if a date is today.

        Parameters:
        date - the date, not altered, not null.
        Returns:
        true if the date is today.
        Throws:
        IllegalArgumentException - if the date is null
      • isToday

        public static boolean isToday​(Calendar cal)

        Checks if a calendar date is today.

        Parameters:
        cal - the calendar, not altered, not null
        Returns:
        true if cal date is today
        Throws:
        IllegalArgumentException - if the calendar is null
      • isBeforeDay

        public static boolean isBeforeDay​(Date date1,
                                          Date date2)

        Checks if the first date is before the second date ignoring time.

        Parameters:
        date1 - the first date, not altered, not null
        date2 - the second date, not altered, not null
        Returns:
        true if the first date day is before the second date day.
        Throws:
        IllegalArgumentException - if the date is null
      • isBeforeDay

        public static boolean isBeforeDay​(Calendar cal1,
                                          Calendar cal2)

        Checks if the first calendar date is before the second calendar date ignoring time.

        Parameters:
        cal1 - the first calendar, not altered, not null.
        cal2 - the second calendar, not altered, not null.
        Returns:
        true if cal1 date is before cal2 date ignoring time.
        Throws:
        IllegalArgumentException - if either of the calendars are null
      • isAfterDay

        public static boolean isAfterDay​(Date date1,
                                         Date date2)

        Checks if the first date is after the second date ignoring time.

        Parameters:
        date1 - the first date, not altered, not null
        date2 - the second date, not altered, not null
        Returns:
        true if the first date day is after the second date day.
        Throws:
        IllegalArgumentException - if the date is null
      • isAfterDay

        public static boolean isAfterDay​(Calendar cal1,
                                         Calendar cal2)

        Checks if the first calendar date is after the second calendar date ignoring time.

        Parameters:
        cal1 - the first calendar, not altered, not null.
        cal2 - the second calendar, not altered, not null.
        Returns:
        true if cal1 date is after cal2 date ignoring time.
        Throws:
        IllegalArgumentException - if either of the calendars are null
      • isWithinDaysFuture

        public static boolean isWithinDaysFuture​(Date date,
                                                 int days)

        Checks if a date is after today and within a number of days in the future.

        Parameters:
        date - the date to check, not altered, not null.
        days - the number of days.
        Returns:
        true if the date day is after today and within days in the future .
        Throws:
        IllegalArgumentException - if the date is null
      • isWithinDaysFuture

        public static boolean isWithinDaysFuture​(Calendar cal,
                                                 int days)

        Checks if a calendar date is after today and within a number of days in the future.

        Parameters:
        cal - the calendar, not altered, not null
        days - the number of days.
        Returns:
        true if the calendar date day is after today and within days in the future .
        Throws:
        IllegalArgumentException - if the calendar is null
      • getStart

        public static Date getStart​(Date date)
        Returns the given date with the time set to the start of the day.
      • clearTime

        public static Date clearTime​(Date date)
        Returns the given date with the time values cleared.
      • hasTime

        public static boolean hasTime​(Date date)
        Determines whether or not a date has any time values.
        Parameters:
        date - The date.
        Returns:
        true iff the date is not null and any of the date's hour, minute, seconds or millisecond values are greater than zero.
      • getEnd

        public static Date getEnd​(Date date)
        Returns the given date with time set to the end of the day
      • max

        public static Date max​(Date d1,
                               Date d2)
        Returns the maximum of two dates. A null date is treated as being less than any non-null date.
      • min

        public static Date min​(Date d1,
                               Date d2)
        Returns the minimum of two dates. A null date is treated as being greater than any non-null date.
      • toList

        public static <T> List<T> toList​(Iterator<T> it)
      • countIterator

        public static int countIterator​(Iterator<?> it)
      • traceString

        public static String traceString​(Throwable t)
        Prints an exceptions trace to a string.
        Parameters:
        t - exception
        Returns:
        trace
      • parseLocale

        public static Locale parseLocale​(String languageCountry)
        Parses the language / country code in a local object
        Parameters:
        languageCountry - language country
        Returns:
        locale
      • isDatePast

        public static boolean isDatePast​(Date fromDate,
                                         int days)
        Calculates if the current time is after the date supplied + the number of days.
        Parameters:
        fromDate -
        days -
        Returns:
      • futureDate

        public static Date futureDate​(long days)
        Calculates the date in the future by adding the supplied days to the current date.
        Parameters:
        days -
        Returns:
        date
      • futureTime

        public static long futureTime​(long days)
        Calculates the time in the future by adding the supplied days to the current time.
        Parameters:
        days -
        Returns:
        time
      • daysToMillis

        public static long daysToMillis​(long days)
        Convert a number of days to milliseconds
        Parameters:
        days - days
        Returns:
        milliseconds
      • assertNotNull

        public static void assertNotNull​(Object toCheck,
                                         String name)
        Asserts that the supplied value is not null.
        Parameters:
        toCheck - the value to check
        name - the name of the supplied value
        Throws:
        IllegalArgumentException - if the supplied value is null.
      • fromObject

        public static String fromObject​(Object object)
        Return a very simple string represent of an object, assuming the object uses bean like getters (getXXX and isXXX). Only looks for zero argument methods and catches exceptions to replace with the text "!Exception!".
        Parameters:
        object - object
        Returns:
        string
      • dayPrecision

        public static Calendar dayPrecision​(Calendar calendar)
        Remove precision from a calendar so that it represents just a day. A new instance is returned
        Parameters:
        calendar - calendar
        Returns:
        new cal
      • removeMe

        public static void removeMe​(String message,
                                    String... args)
        Temporary debugging. References to this method should be checked before release.
        Parameters:
        message - message pattern
        args - message arguments
      • randomSleep

        public static void randomSleep​(long ms)
        Sleep for a short random amount of time
        Parameters:
        ms - max time
      • differs

        public static boolean differs​(Object o1,
                                      Object o2)
      • memDbg

        public static void memDbg​(String ctx)