compareEntityIDs function
Compares 2 entity IDs, implementing the orderByID ordering of the
select* methods.
nullIDs are ordered last (in OrderDirection.ascending order).- nums are compared numerically and Strings lexicographically.
- Any other pair of Comparables of the same type is compared
with Comparable.compareTo; otherwise returns
0(undefined order).
Implementation
int compareEntityIDs(Object? id1, Object? id2) {
if (identical(id1, id2)) return 0;
if (id1 == null) return id2 == null ? 0 : 1;
if (id2 == null) return -1;
if (id1 is num && id2 is num) return id1.compareTo(id2);
if (id1 is String && id2 is String) return id1.compareTo(id2);
if (id1 is Comparable && id2 is Comparable) {
if (id1.runtimeType == id2.runtimeType) {
return id1.compareTo(id2);
}
}
return 0;
}