|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jidesoft.comparator.ObjectComparatorManager
public class ObjectComparatorManager
A global object that can register comparator with a type and a ComparatorContext.
Constructor Summary | |
---|---|
ObjectComparatorManager()
|
Method Summary | |
---|---|
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 int |
compare(Object o1,
Object o2)
Compares the two objects. |
static int |
compare(Object o1,
Object o2,
Class<?> clazz)
Compares the two objects. |
static int |
compare(Object o1,
Object o2,
Class<?> clazz,
ComparatorContext context)
Compares the two objects. |
static int |
compare(Object o1,
Object o2,
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[] |
getRegistrationListeners()
Returns an array of all the registration listeners registered on this manager. |
static void |
initDefaultComparator()
Initialize default comparator. |
static boolean |
isAutoInit()
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 |
removeRegistrationListener(RegistrationListener l)
Removes a listener from the list that's notified each time a change to the manager occurs. |
static void |
resetInit()
If initDefaultComparator() 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 |
unregisterAllComparators()
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectComparatorManager()
Method Detail |
---|
public static void registerComparator(Class<?> clazz, Comparator comparator)
public static void registerComparator(Class<?> clazz, Comparator comparator, ComparatorContext context)
clazz
- type.comparator
- the comparator to be registered.context
- the comparator context.public static void unregisterComparator(Class<?> clazz)
clazz
- the data type.public static void unregisterComparator(Class<?> clazz, ComparatorContext context)
clazz
- the data type.context
- the comparator context.public static void unregisterAllComparators(Class<?> clazz)
clazz
- the data type.public static void unregisterAllComparators()
public static Comparator getComparator(Class<?> clazz)
clazz
- the data type.
public static Comparator getComparator(Class<?> clazz, ComparatorContext context)
clazz
- the data type.context
- the comparator context.
public static int compare(Object o1, Object o2)
ObjectComparatorManager
to find the comparator and
compare.
o1
- the first object to be compared.o2
- the second object to be compared.
Comparator.compare(Object, Object)
public static int compare(Object o1, Object o2, ComparatorContext context)
ObjectComparatorManager
to find the comparator and
compare.
o1
- the first object to be compared.o2
- the second object to be compared.context
- the comparator context
Comparator.compare(Object, Object)
public static int compare(Object o1, Object o2, Class<?> clazz)
ObjectComparatorManager
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 in ObjectComparatorManager
.
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 use compare(Object, Object)
methods.
Comparator.compare(Object, Object)
public static int compare(Object o1, Object o2, Class<?> clazz, ComparatorContext context)
ObjectComparatorManager
to find the comparator and
compare. If it is not found, we will convert the object to string and compare the two strings.
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 use compare(Object, Object)
methods.context
- the comparator context
Comparator.compare(Object, Object)
public static boolean isAutoInit()
setAutoInit(boolean)
public static void setAutoInit(boolean autoInit)
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 call initDefaultComparator()
first, then call registerComparator to add your own comparators.
autoInit
- false if you want to disable autoInit which means you either don't want those default comparators
registered or you will call initDefaultComparator()
yourself.public static void addRegistrationListener(RegistrationListener l)
l
- the RegistrationListenerpublic static void removeRegistrationListener(RegistrationListener l)
l
- the RegistrationListenerpublic static RegistrationListener[] getRegistrationListeners()
RegistrationListener
s or an empty array if no registration
listeners are currently registeredaddRegistrationListener(com.jidesoft.utils.RegistrationListener)
,
removeRegistrationListener(com.jidesoft.utils.RegistrationListener)
public static ComparatorContext[] getComparatorContexts(Class<?> clazz)
clazz
- the class.
public static void initDefaultComparator()
public static void resetInit()
initDefaultComparator()
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 initDefaultComparator()
in case
you unregister all comparators using unregisterAllComparators()
.
public static void clear()
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |