public final int compare(Object object1,
Object object2) {
Object obj1 = null;
Object obj2 = null;
// if property is null compare using two static cell objects
if (this.property == null)
{
if (object1 instanceof Row)
{
obj1 = ((Row) object1).getCellList().get(this.columnIndex);
}
if (object2 instanceof Row)
{
obj2 = ((Row) object2).getCellList().get(this.columnIndex);
}
return checkNullsAndCompare(obj1, obj2);
}
if (object1 instanceof Row)
{
obj1 = ((Row) object1).getObject();
}
if (object2 instanceof Row)
{
obj2 = ((Row) object2).getObject();
}
try
{
Object result1;
Object result2;
// If they have supplied a decorator, then make sure and use it for the sorting as well
if (this.decorator != null && this.decorator.hasGetterFor(this.property))
{
// set the row before sending to the decorator
this.decorator.initRow(obj1, 0, 0);
result1 = LookupUtil.getBeanProperty(this.decorator, this.property);
// set the row before sending to the decorator
this.decorator.initRow(obj2, 0, 0);
result2 = LookupUtil.getBeanProperty(this.decorator, this.property);
}
else
{
result1 = LookupUtil.getBeanProperty(obj1, this.property);
result2 = LookupUtil.getBeanProperty(obj2, this.property);
}
return checkNullsAndCompare(result1, result2);
}
catch (ObjectLookupException e)
{
throw new RuntimeLookupException(getClass(), this.property, e);
}
}
Compares two objects by first fetching a property from each object and then comparing that value. If there are
any errors produced while trying to compare these objects then a RunTimeException will be thrown as any error
found here will most likely be a programming error that needs to be quickly addressed (like trying to compare
objects that are not comparable, or trying to read a property from a bean that is invalid, etc...) |