compareTo method

  1. @override
int compareTo(
  1. Path other
)
override

Compares segment by segment with the child-key order; a prefix sorts first.

Implementation

@override
int compareTo(Path other) {
  final List<ChildKey> mine = segments;
  final List<ChildKey> theirs = other.segments;
  final int common = mine.length < theirs.length
      ? mine.length
      : theirs.length;
  for (int i = 0; i < common; i++) {
    final int cmp = mine[i].compareTo(theirs[i]);
    if (cmp != 0) {
      return cmp;
    }
  }
  return mine.length == theirs.length
      ? 0
      : (mine.length < theirs.length ? -1 : 1);
}