Class ObjectGrouperManager


  • public class ObjectGrouperManager
    extends java.lang.Object
    A global object that can register Object Grouper with a type and a GrouperContext.
    • Constructor Detail

      • ObjectGrouperManager

        public ObjectGrouperManager()
    • 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 - type
        grouper - group to be registered
        context - 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 object
        context - 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 call initDefaultGrouper() 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 call initDefaultGrouper() 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
      • 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);
         
      • clear

        public static void clear()