int typecompare = t1.compareTo(t2);
if (typecompare != 0) return typecompare;
assert t1.equals(t2);
//2) Direction
Direction dir1 = null, dir2 = null;
for (int i = 0; i < r1.getLen(); i++)
if (r1.getVertex(i).equals(vertex)) {
dir1 = EdgeDirection.fromPosition(i);
break;
}
for (int i = 0; i < r2.getLen(); i++)
if (r2.getVertex(i).equals(vertex)) {
dir2 = EdgeDirection.fromPosition(i);
break;
}
assert dir1 != null && dir2 != null; // ("Either relation is not incident on vertex [%s]", vertex);
int dirCompare = EdgeDirection.position(dir1) - EdgeDirection.position(dir2);
if (dirCompare != 0) return dirCompare;
// Breakout: If type&direction are the same and the type is unique in the direction it follows that the relations are the same
if (t1.isUnique(dir1)) return 0;
// 3) Compare sort key values
for (long typeid : t1.getSortKey()) {
int keycompare = compareOnKey(r1, r2, typeid, t1.getSortOrder());
if (keycompare != 0) return keycompare;
}
// 4) Compare property objects or other vertices
if (r1.isProperty()) {
Object o1 = ((TitanProperty) r1).getValue();
Object o2 = ((TitanProperty) r2).getValue();
Preconditions.checkArgument(o1 != null && o2 != null);
if (!o1.equals(o2)) {
int objectcompare = 0;
if (Comparable.class.isAssignableFrom(((TitanKey) t1).getDataType())) {
objectcompare = ((Comparable) o1).compareTo(o2);
} else {
objectcompare = System.identityHashCode(o1) - System.identityHashCode(o2);
}
if (objectcompare != 0) return objectcompare;
}
} else {
Preconditions.checkArgument(r1.isEdge() && r2.isEdge());
int vertexcompare = r1.getVertex(EdgeDirection.position(dir1.opposite())).
compareTo(r2.getVertex(EdgeDirection.position(dir1.opposite())));
if (vertexcompare != 0) return vertexcompare;
}
//TODO: if graph is simple, return 0
// 5)compare relation ids
return r1.compareTo(r2);