Class DateGrouper

java.lang.Object
com.jidesoft.grouper.AbstractObjectGrouper
com.jidesoft.grouper.date.DateGrouper
All Implemented Interfaces:
ObjectGrouper
Direct Known Subclasses:
DateDayOfMonthGrouper, DateDayOfWeekGrouper, DateDayOfWeekInMonthGrouper, DateDayOfYearGrouper, DateMonthGrouper, DateQuarterGrouper, DateWeekOfMonthGrouper, DateWeekOfYearGrouper, DateYearGrouper

public abstract class DateGrouper extends AbstractObjectGrouper
An abstract Grouper which can take data type such as Date, Calendar or Long and provide getCalendarFieldAsInt(Object, int) and getCalendarField(Object, int) methods to access the field of the Calendar.
  • Field Details

    • INSTANCE

      protected static Calendar INSTANCE
  • Constructor Details

    • DateGrouper

      public DateGrouper()
  • Method Details

    • getCalendarInstance

      public static 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 Object getCalendarField(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:
      IllegalArgumentException - if the value is not a Date, a Long or a Calendar.
    • getCalendarFieldAsInt

      public static int getCalendarFieldAsInt(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:
      IllegalArgumentException - if the value is not a Date, a Long or a Calendar.
    • getType

      public 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.