Class ObjectGrouperManager

java.lang.Object
com.jidesoft.grouper.ObjectGrouperManager

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

    • ObjectGrouperManager

      public ObjectGrouperManager()
  • Method Details

    • registerGrouper

      public 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.
      Parameters:
      clazz - type
      grouper - group to be registered
      context - the grouper context.
    • registerGrouper

      public static void registerGrouper(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(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(Class<?> clazz)
      Unregisters grouper associated with clazz.
      Parameters:
      clazz - the data type.
    • unregisterAllGroupers

      public static void unregisterAllGroupers(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(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(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 Object getGroupValue(Object object)
      Converts an object to string using default grouper context.
      Parameters:
      object - object to be converted.
      Returns:
      the string
    • getGroupValue

      public static Object getGroupValue(Object object, 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 Object getGroupValue(Object object, 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

      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
    • getRegistrationListeners

      public static RegistrationListener[] getRegistrationListeners()
      Returns an array of all the registration listeners registered on this manager.
      Returns:
      all of this registration's RegistrationListeners or an empty array if no registration listeners are currently registered
      See Also:
    • getGrouperContexts

      public static GrouperContext[] getGrouperContexts(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()
      If initDefaultGrouper() 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 call initDefaultGrouper() in case you unregister all groupers using unregisterAllGroupers().
    • clear

      public static void clear()