Class DateGrouper

    • Field Detail

      • INSTANCE

        protected static java.util.Calendar INSTANCE
    • Constructor Detail

      • DateGrouper

        public DateGrouper()
    • Method Detail

      • getCalendarInstance

        public static java.util.Calendar getCalendarInstance()
        To avoid creating too many instance of Calendar and improve the performance, getCalendarField(Object, int) and getCalendarFieldAsInt(Object, int) will use a cached instance of Calendar if the value passed in is Date or Long. By default, the cached Calendar instance was created from Calendar.getInstance(). This method will give you this instance and allow you to modify it. For example, setting a different time-zone. Since this instance is static, there is only one instance for the whole application. So just so you know, if you modify it, it will affect all the usages.
        Returns:
        the Calendar instance used by the two getCalendarField methods.
      • getCalendarField

        public static java.lang.Object getCalendarField​(java.lang.Object value,
                                                        int field)
        Gets the field value from the value.
        Parameters:
        value - a Date, Long or Calendar. If the value is a Date or a Long, we will use a cached Calendar instance to get the field value. This cached Calendar instance can be retrieved using getCalendarInstance() in case you want to customize it.
        field - the field as defined in Calendar such as Calender.YEAR, Calendar.DAY_OF_MONTH.
        Returns:
        the field value. Null if the value that was passed in is null.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a Date, a Long or a Calendar.
      • getCalendarFieldAsInt

        public static int getCalendarFieldAsInt​(java.lang.Object value,
                                                int field)
        Gets the field value from the value.
        Parameters:
        value - a Date, Long or Calendar. If the value is a Date or a Long, we will use a cached Calendar instance to get the field value. This cached Calendar instance can be retrieved using getCalendarInstance() in case you want to customize it.
        field - the field as defined in Calendar such as Calender.YEAR, Calendar.DAY_OF_MONTH.
        Returns:
        the field value. -1 if the value that was passed in is null.
        Throws:
        java.lang.IllegalArgumentException - if the value is not a Date, a Long or a Calendar.
      • getType

        public java.lang.Class<?> getType()
        Description copied from interface: ObjectGrouper
        Gets the group value type. It should be the type of the value that is returned from the getGroupValue.
        Returns:
        the group value type.