Package com.jidesoft.grouper
Class ObjectGrouperManager
java.lang.Object
com.jidesoft.grouper.ObjectGrouperManager
A global object that can register Object Grouper with a type and a GrouperContext.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Adds a listener to the list that's notified each time a change to the manager occurs.static void
clear()
static ObjectGrouper
getGrouper
(Class<?> clazz) Gets the grouper associated with the type.static ObjectGrouper
getGrouper
(Class<?> clazz, GrouperContext context) Gets the registered grouper associated with class and context.static GrouperContext[]
getGrouperContexts
(Class<?> clazz) Gets the available GrouperContexts registered with the class.static Object
getGroupValue
(Object object) Converts an object to string using default grouper context.static Object
getGroupValue
(Object object, Class<?> clazz) Converts an object to string using default grouper context.static Object
getGroupValue
(Object object, Class<?> clazz, GrouperContext context) Converts an object to string using grouper context specified.static RegistrationListener[]
Returns an array of all the registration listeners registered on this manager.static void
Initialize default groupers.static boolean
Checks the value of autoInit.static void
registerGrouper
(Class<?> clazz, ObjectGrouper grouper) Registers a grouper with type specified as clazz.static void
registerGrouper
(Class<?> clazz, ObjectGrouper grouper, GrouperContext context) Registers a grouper with the type specified as class and a grouper context specified as context.static void
Removes a listener from the list that's notified each time a change to the manager occurs.static void
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
Unregisters all the groupers which registered before.static void
unregisterAllGroupers
(Class<?> clazz) Unregisters all groupers associated with clazz.static void
unregisterGrouper
(Class<?> clazz) Unregisters grouper associated with clazz.static void
unregisterGrouper
(Class<?> clazz, GrouperContext context) Unregisters grouper associated with clazz and context.
-
Constructor Details
-
ObjectGrouperManager
public ObjectGrouperManager()
-
-
Method Details
-
registerGrouper
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
Registers a grouper with type specified as clazz.- Parameters:
clazz
- the data type.grouper
- the grouper to be registered
-
unregisterGrouper
Unregisters grouper associated with clazz and context.- Parameters:
clazz
- the data type.context
- the grouper context.
-
unregisterGrouper
Unregisters grouper associated with clazz.- Parameters:
clazz
- the data type.
-
unregisterAllGroupers
Unregisters all groupers associated with clazz.- Parameters:
clazz
- the data type.
-
unregisterAllGroupers
public static void unregisterAllGroupers()Unregisters all the groupers which registered before. -
getGrouper
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
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
Converts an object to string using default grouper context.- Parameters:
object
- object to be converted.- Returns:
- the string
-
getGroupValue
Converts an object to string using default grouper context.- Parameters:
object
- object to be converted.clazz
- type of the object- Returns:
- the string
-
getGroupValue
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
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
Adds a listener to the list that's notified each time a change to the manager occurs.- Parameters:
l
- the RegistrationListener
-
removeRegistrationListener
Removes a listener from the list that's notified each time a change to the manager occurs.- Parameters:
l
- the 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:
-
getGrouperContexts
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()
-