int result = 0;
for (Iterator<SortField2> iterator = sortFields.iterator(); iterator.hasNext() && result == 0;) {
SortField2 field = iterator.next();
Expression expression = field.getExpression();
Ordering ordering = field.getOrdering();
if (ordering != null) {
Object p1 = w1.getProperty(expression);
Object p2 = w2.getProperty(expression);
if (p1 == p2 && p1 instanceof Comparator) {
result = ((Comparator<Object>)p1).compare(w1.getWrappedObject(), w2.getWrappedObject());
} else if (p1 instanceof String && p2 instanceof String) {
if (stringComparator == null) {
stringComparator = createStringComparator();
}
result = stringComparator.compare(((String)p1).trim(), ((String)p2).trim());
} else if (p1 instanceof Comparable && p2 instanceof Comparable) {
result = ((Comparable<Object>) p1).compareTo(p2);
} else if (p1 == null && p2 != null) {
result = -1;
} else if (p2 == null && p1 != null) {
result = 1;
}
if (ordering.equals(Ordering.DESCENDING)) {
result = -result;
}
}
}