@Override public int compare(Statement first, Statement second) { // Cannot use Statement.equals as it does not take Context into account, // but can check for reference equality (==) if (first == second) { return EQUAL; } if (first.getSubject().equals(second.getSubject())) { if (first.getPredicate().equals(second.getPredicate())) { if (first.getObject().equals(second.getObject())) { // Context is the only part of a statement that should legitimately be null if (first.getContext() == null) { if (second.getContext() == null) { return EQUAL; } else { return BEFORE; } } else if (second.getContext() == null) { return AFTER; } else { return ValueComparator.getInstance().compare(first.getContext(), second.getContext()); } } else { return ValueComparator.getInstance().compare(first.getObject(), second.getObject()); } } else { return ValueComparator.getInstance().compare(first.getPredicate(), second.getPredicate()); } } else { return ValueComparator.getInstance().compare(first.getSubject(), second.getSubject()); } }
@Override public int hashCode() { if (hashCode == 0) { int result = 17; result = 37 * result + val.hashCode(); result = 37 * result + comp.hashCode(); hashCode = result; } return hashCode; }
@Override public String getFormatted() { return comp.getComparatorString() + " " + val.getFormatted(); }