Package com.jidesoft.grouper
Class ObjectGrouperManager
- java.lang.Object
-
- com.jidesoft.grouper.ObjectGrouperManager
-
public class ObjectGrouperManager extends java.lang.Object
A global object that can register Object Grouper with a type and a GrouperContext.
-
-
Constructor Summary
Constructors Constructor Description ObjectGrouperManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addRegistrationListener(RegistrationListener l)
Adds a listener to the list that's notified each time a change to the manager occurs.static void
clear()
static ObjectGrouper
getGrouper(java.lang.Class<?> clazz)
Gets the grouper associated with the type.static ObjectGrouper
getGrouper(java.lang.Class<?> clazz, GrouperContext context)
Gets the registered grouper associated with class and context.static GrouperContext[]
getGrouperContexts(java.lang.Class<?> clazz)
Gets the available GrouperContexts registered with the class.static java.lang.Object
getGroupValue(java.lang.Object object)
Converts an object to string using default grouper context.static java.lang.Object
getGroupValue(java.lang.Object object, java.lang.Class<?> clazz)
Converts an object to string using default grouper context.static java.lang.Object
getGroupValue(java.lang.Object object, java.lang.Class<?> clazz, GrouperContext context)
Converts an object to string using grouper context specified.static RegistrationListener[]
getRegistrationListeners()
Returns an array of all the registration listeners registered on this manager.static void
initDefaultGrouper()
Initialize default groupers.static boolean
isAutoInit()
Checks the value of autoInit.static void
registerGrouper(java.lang.Class<?> clazz, ObjectGrouper grouper)
Registers a grouper with type specified as clazz.static void
registerGrouper(java.lang.Class<?> clazz, ObjectGrouper grouper, GrouperContext context)
Registers a grouper with the type specified as class and a grouper context specified as context.static void
removeRegistrationListener(RegistrationListener l)
Removes a listener from the list that's notified each time a change to the manager occurs.static void
resetInit()
IfinitDefaultGrouper()
is called once, calling it again will have no effect because an internal flag is set.static void
setAutoInit(boolean autoInit)
Sets autoInit to true or false.static void
unregisterAllGroupers()
Unregisters all the groupers which registered before.static void
unregisterAllGroupers(java.lang.Class<?> clazz)
Unregisters all groupers associated with clazz.static void
unregisterGrouper(java.lang.Class<?> clazz)
Unregisters grouper associated with clazz.static void
unregisterGrouper(java.lang.Class<?> clazz, GrouperContext context)
Unregisters grouper associated with clazz and context.
-
-
-
Method Detail
-
registerGrouper
public static void registerGrouper(java.lang.Class<?> clazz, ObjectGrouper grouper, GrouperContext context)
Registers a grouper with the type specified as class and a grouper context specified as context.- Parameters:
clazz
- typegrouper
- group to be registeredcontext
- the grouper context.
-
registerGrouper
public static void registerGrouper(java.lang.Class<?> clazz, ObjectGrouper grouper)
Registers a grouper with type specified as clazz.- Parameters:
clazz
- the data type.grouper
- the grouper to be registered
-
unregisterGrouper
public static void unregisterGrouper(java.lang.Class<?> clazz, GrouperContext context)
Unregisters grouper associated with clazz and context.- Parameters:
clazz
- the data type.context
- the grouper context.
-
unregisterGrouper
public static void unregisterGrouper(java.lang.Class<?> clazz)
Unregisters grouper associated with clazz.- Parameters:
clazz
- the data type.
-
unregisterAllGroupers
public static void unregisterAllGroupers(java.lang.Class<?> clazz)
Unregisters all groupers associated with clazz.- Parameters:
clazz
- the data type.
-
unregisterAllGroupers
public static void unregisterAllGroupers()
Unregisters all the groupers which registered before.
-
getGrouper
public static ObjectGrouper getGrouper(java.lang.Class<?> clazz, GrouperContext context)
Gets the registered grouper associated with class and context.- Parameters:
clazz
- the data type.context
- the grouper context.- Returns:
- the registered grouper. It could return null if there is no grouper for the type and the context.
-
getGrouper
public static ObjectGrouper getGrouper(java.lang.Class<?> clazz)
Gets the grouper associated with the type.- Parameters:
clazz
- the data type.- Returns:
- the grouper. It could return null if there is no grouper for the type.
-
getGroupValue
public static java.lang.Object getGroupValue(java.lang.Object object)
Converts an object to string using default grouper context.- Parameters:
object
- object to be converted.- Returns:
- the string
-
getGroupValue
public static java.lang.Object getGroupValue(java.lang.Object object, java.lang.Class<?> clazz)
Converts an object to string using default grouper context.- Parameters:
object
- object to be converted.clazz
- type of the object- Returns:
- the string
-
getGroupValue
public static java.lang.Object getGroupValue(java.lang.Object object, java.lang.Class<?> clazz, GrouperContext context)
Converts an object to string using grouper context specified.- Parameters:
object
- object to be converted.clazz
- type of the objectcontext
- group context- Returns:
- the string converted from object
-
isAutoInit
public static boolean isAutoInit()
Checks the value of autoInit.- Returns:
- true or false.
- See Also:
setAutoInit(boolean)
-
setAutoInit
public static void setAutoInit(boolean autoInit)
Sets autoInit to true or false. If autoInit is true, whenever someone tries to call methods getValue,initDefaultGrouper()
will be called if it has never be called. By default, autoInit is true. This might affect the behavior if users provide their own groupers and want to overwrite default groupers. In this case, instead of depending on autoInit to initialize default groupers, you should callinitDefaultGrouper()
first, then call registerGrouper to add your own groupers.- Parameters:
autoInit
- false if you want to disable autoInit which means you either don't want those default comparators registered or you will callinitDefaultGrouper()
yourself.
-
addRegistrationListener
public static void addRegistrationListener(RegistrationListener l)
Adds a listener to the list that's notified each time a change to the manager occurs.- Parameters:
l
- the RegistrationListener
-
removeRegistrationListener
public static void removeRegistrationListener(RegistrationListener l)
Removes a listener from the list that's notified each time a change to the manager occurs.- Parameters:
l
- the RegistrationListener
-
getRegistrationListeners
public static RegistrationListener[] getRegistrationListeners()
Returns an array of all the registration listeners registered on this manager.- Returns:
- all of this registration's
RegistrationListener
s or an empty array if no registration listeners are currently registered - See Also:
addRegistrationListener(com.jidesoft.utils.RegistrationListener)
,removeRegistrationListener(com.jidesoft.utils.RegistrationListener)
-
getGrouperContexts
public static GrouperContext[] getGrouperContexts(java.lang.Class<?> clazz)
Gets the available GrouperContexts registered with the class.- Parameters:
clazz
- the class.- Returns:
- the available GrouperContexts.
-
initDefaultGrouper
public static void initDefaultGrouper()
Initialize default groupers. Please make sure you call this method before you use any group related classes. By default we register following groupers.DateYearGrouper dateYearGrouper = new DateYearGrouper(); registerGrouper(Date.class, dateYearGrouper, DateYearGrouper.CONTEXT); registerGrouper(Calendar.class, dateYearGrouper, DateYearGrouper.CONTEXT); registerGrouper(Long.class, dateYearGrouper, DateYearGrouper.CONTEXT); DateMonthGrouper dateMonthGrouper = new DateMonthGrouper(); registerGrouper(Date.class, dateMonthGrouper, DateMonthGrouper.CONTEXT); registerGrouper(Calendar.class, dateMonthGrouper, DateMonthGrouper.CONTEXT); registerGrouper(Long.class, dateMonthGrouper, DateMonthGrouper.CONTEXT);
-
resetInit
public static void resetInit()
IfinitDefaultGrouper()
is called once, calling it again will have no effect because an internal flag is set. This method will reset the internal flag so that you can callinitDefaultGrouper()
in case you unregister all groupers usingunregisterAllGroupers()
.
-
clear
public static void clear()
-
-