diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java index e2ba33d2c..da32fc61c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/beans/DataPropertyComparator.java @@ -15,26 +15,33 @@ public class DataPropertyComparator implements Comparator { } public int compare(Individual ind1, Individual ind2) { - DataPropertyStatement s1 = ind1.getDataPropertyStatement(dataPropertyUri); - DataPropertyStatement s2 = ind2.getDataPropertyStatement(dataPropertyUri); - - String datatype = s1.getDatatypeURI(); - + DataPropertyStatement dps1 = ind1.getDataPropertyStatement(dataPropertyUri); + DataPropertyStatement dps2 = ind2.getDataPropertyStatement(dataPropertyUri); + int result; - if (datatype.equals(XSD.xint.toString())) { - int i1 = Integer.valueOf(s1.getData()); - int i2 = Integer.valueOf(s2.getData()); - result = ((Integer) i1).compareTo(i2); - } - else if (datatype.equals(XSD.xstring.toString())) { - result = s1.getData().compareTo(s2.getData()); - } - // Fill in other types here - else { - throw new ClassCastException("Unsupported datatype"); - } + // This pushes null values to the end of the list + if (dps1 == null) { + result = (dps2 == null) ? 0 : 1; + } else if (dps2 == null) { + result = -1; + } else { + + String datatype = dps1.getDatatypeURI(); + if (datatype.equals(XSD.xint.toString())) { + int i1 = Integer.valueOf(dps1.getData()); + int i2 = Integer.valueOf(dps2.getData()); + result = ((Integer) i1).compareTo(i2); + } + else if (datatype.equals(XSD.xstring.toString())) { + result = dps1.getData().compareTo(dps2.getData()); + } + // Fill in other types here + else { + throw new ClassCastException("Unsupported datatype"); + } + } return result; }