Package com.jidesoft.comparator
Class ObjectComparatorManager
java.lang.Object
com.jidesoft.comparator.ObjectComparatorManager
A global object that can register comparator with a type and a ComparatorContext.
-
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 int
Compares the two objects.static int
compare
(Object o1, Object o2, ComparatorContext context) Compares the two objects.static int
Compares the two objects.static int
compare
(Object o1, Object o2, Class<?> clazz, ComparatorContext context) Compares the two objects.static Comparator
getComparator
(Class<?> clazz) Gets the registered comparator associated with class and default context.static Comparator
getComparator
(Class<?> clazz, ComparatorContext context) Gets the comparator.static ComparatorContext[]
getComparatorContexts
(Class<?> clazz) Gets the available ComparatorContexts registered with the class.static RegistrationListener[]
Returns an array of all the registration listeners registered on this manager.static void
Initialize default comparator.static boolean
Checks the value of autoInit.static void
registerComparator
(Class<?> clazz, Comparator comparator) static void
registerComparator
(Class<?> clazz, Comparator comparator, ComparatorContext context) Registers a comparator with the type specified as class and a comparator 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
IfinitDefaultComparator()
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 comparators which registered before.static void
unregisterAllComparators
(Class<?> clazz) Unregisters all comparators associated with the class.static void
unregisterComparator
(Class<?> clazz) Unregisters comparator associated with the class and context.static void
unregisterComparator
(Class<?> clazz, ComparatorContext context) Unregisters comparator associated with the class and context.
-
Constructor Details
-
ObjectComparatorManager
public ObjectComparatorManager()
-
-
Method Details
-
registerComparator
-
registerComparator
public static void registerComparator(Class<?> clazz, Comparator comparator, ComparatorContext context) Registers a comparator with the type specified as class and a comparator context specified as context.- Parameters:
clazz
- type.comparator
- the comparator to be registered.context
- the comparator context.
-
unregisterComparator
Unregisters comparator associated with the class and context.- Parameters:
clazz
- the data type.
-
unregisterComparator
Unregisters comparator associated with the class and context.- Parameters:
clazz
- the data type.context
- the comparator context.
-
unregisterAllComparators
Unregisters all comparators associated with the class.- Parameters:
clazz
- the data type.
-
unregisterAllComparators
public static void unregisterAllComparators()Unregisters all the comparators which registered before. -
getComparator
Gets the registered comparator associated with class and default context.- Parameters:
clazz
- the data type.- Returns:
- the registered comparator.
-
getComparator
Gets the comparator.- Parameters:
clazz
- the data type.context
- the comparator context.- Returns:
- the comparator.
-
compare
Compares the two objects. It will look up inObjectComparatorManager
to find the comparator and compare.- Parameters:
o1
- the first object to be compared.o2
- the second object to be compared.- Returns:
- the compare result as defined in
Comparator.compare(Object, Object)
-
compare
Compares the two objects. It will look up inObjectComparatorManager
to find the comparator and compare.- Parameters:
o1
- the first object to be compared.o2
- the second object to be compared.context
- the comparator context- Returns:
- the compare result as defined in
Comparator.compare(Object, Object)
-
compare
Compares the two objects. It will look up inObjectComparatorManager
to find the comparator and compare. This method needs a third parameter which is the data type. This is useful when you have two objects that have different data types but both extend the same super class. In this case, you may want the super class as the key to look up inObjectComparatorManager
.- Parameters:
o1
- the first object to be compared.o2
- the second object to be compared.clazz
- the data type of the two objects. If your two objects have the same type, you may just usecompare(Object, Object)
methods.- Returns:
- the compare result as defined in
Comparator.compare(Object, Object)
-
compare
Compares the two objects. It will look up inObjectComparatorManager
to find the comparator and compare. If it is not found, we will convert the object to string and compare the two strings.- Parameters:
o1
- the first object to be compared.o2
- the second object to be compared.clazz
- the data type of the two objects. If your two objects have the same type, you may just usecompare(Object, Object)
methods.context
- the comparator context- Returns:
- the compare result as defined in
Comparator.compare(Object, 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 like as toString or fromString,initDefaultComparator()
will be called if it has never be called. By default, autoInit is true. This might affect the behavior if users provide their own comparators and want to overwrite default comparators. In this case, instead of depending on autoInit to initialize default comparators, you should callinitDefaultComparator()
first, then call registerComparator to add your own comparators.- Parameters:
autoInit
- false if you want to disable autoInit which means you either don't want those default comparators registered or you will callinitDefaultComparator()
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:
-
getComparatorContexts
Gets the available ComparatorContexts registered with the class.- Parameters:
clazz
- the class.- Returns:
- the available ComparatorContext.
-
initDefaultComparator
public static void initDefaultComparator()Initialize default comparator. Please make sure you call this method before you use any comparator related classes such as SortableTableModel. -
resetInit
public static void resetInit()IfinitDefaultComparator()
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 callinitDefaultComparator()
in case you unregister all comparators usingunregisterAllComparators()
. -
clear
public static void clear()
-