static class ValueComparator implements Comparator<Value> {
public int compare(Value o1, Value o2) {
if (o1 instanceof Literal) {
if (o2 instanceof Literal) {
Literal l1 = (Literal)o1;
Literal l2 = (Literal)o2;
if (l1.getLanguage() != null && l2.getLanguage() != null) {
int l = l1.getLanguage().compareTo(l2.getLanguage());
return l != 0 ? l : o1.stringValue().compareTo(o2.stringValue());
}
else if (l1.getLanguage() != null) {
return -1;
}
else if (l2.getLanguage() != null) {
return 1;
}
if (l1.getDatatype() != null && l2.getDatatype() != null) {
int d = l1.getDatatype().stringValue().compareTo(l2.getDatatype().stringValue());
return d != 0 ? d : o1.stringValue().compareTo(o2.stringValue());
}
else if (l1.getDatatype() != null) {
return -1;
}
else if (l2.getDatatype() != null) {
return 1;
}
}
}
return o1.stringValue().compareTo(o2.stringValue());