Groovy Documentation

com.wordpress.tipsforjava.util
[Java] Class BeanComparator

java.lang.Object
  com.wordpress.tipsforjava.util.BeanComparator
All Implemented Interfaces:
Comparator

public class BeanComparator
extends Object

A comparator to sort on the specified field of a given class. Reflection is used to retrieve the data to be sorted, therefore you must provide the Class and the method name within the class that will be used to retrieve the data. Several sort properties can be set: a) ascending (default true) b) ignore case (default true) c) nulls last (default true)

Authors:
Rob Camick
Darryl Burke


Field Summary
private static Class[] EMPTY_CLASS_ARRAY

private static Object[] EMPTY_OBJECT_ARRAY

private boolean isAscending

private boolean isIgnoreCase

private boolean isNullsLast

private Method method

 
Constructor Summary
BeanComparator(Class beanClass, String methodName)

BeanComparator(Class beanClass, String methodName, boolean isAscending)

BeanComparator(Class beanClass, String methodName, boolean isAscending, boolean isIgnoreCase)

 
Method Summary
int compare(Object object1, Object object2)

void setAscending(boolean isAscending)

void setIgnoreCase(boolean isIgnoreCase)

void setNullsLast(boolean isNullsLast)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

EMPTY_CLASS_ARRAY

private static final Class[] EMPTY_CLASS_ARRAY


EMPTY_OBJECT_ARRAY

private static final Object[] EMPTY_OBJECT_ARRAY


isAscending

private boolean isAscending


isIgnoreCase

private boolean isIgnoreCase


isNullsLast

private boolean isNullsLast


method

private Method method


 
Constructor Detail

BeanComparator

BeanComparator(Class beanClass, String methodName)


BeanComparator

BeanComparator(Class beanClass, String methodName, boolean isAscending)


BeanComparator

BeanComparator(Class beanClass, String methodName, boolean isAscending, boolean isIgnoreCase)


 
Method Detail

compare

ssWarnings("unchecked")
	public
public int compare(Object object1, Object object2)


setAscending

public void setAscending(boolean isAscending)


setIgnoreCase

public void setIgnoreCase(boolean isIgnoreCase)


setNullsLast

public void setNullsLast(boolean isNullsLast)


 

Groovy Documentation