Package com.jidesoft.grouper.date
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 providegetCalendarFieldAsInt(Object, int)
andgetCalendarField(Object, int)
methods to access the field of the Calendar.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.util.Calendar
INSTANCE
-
Constructor Summary
Constructors Constructor Description DateGrouper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
getCalendarField(java.lang.Object value, int field)
Gets the field value from the value.static int
getCalendarFieldAsInt(java.lang.Object value, int field)
Gets the field value from the value.static java.util.Calendar
getCalendarInstance()
To avoid creating too many instance of Calendar and improve the performance,getCalendarField(Object, int)
andgetCalendarFieldAsInt(Object, int)
will use a cached instance of Calendar if the value passed in is Date or Long.java.lang.Class<?>
getType()
Gets the group value type.-
Methods inherited from class com.jidesoft.grouper.AbstractObjectGrouper
getComparatorContext, getConverterContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.jidesoft.grouper.ObjectGrouper
getName, getValue
-
-
-
-
Method Detail
-
getCalendarInstance
public static java.util.Calendar getCalendarInstance()
To avoid creating too many instance of Calendar and improve the performance,getCalendarField(Object, int)
andgetCalendarFieldAsInt(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 usinggetCalendarInstance()
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 usinggetCalendarInstance()
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.
-
-