cmp method

int cmp(
  1. Iterator<U> other
)

Lexicographically compares the elements of this Iterator with those of another. Less = -1 Equal = 0 Greater = 1

Implementation

int cmp(Iterator<U> other) {
  while (true) {
    if (moveNext()) {
      if (other.moveNext()) {
        final cmp = current.compareTo(other.current);
        if (cmp != 0) {
          return cmp;
        }
      } else {
        return 1;
      }
    } else {
      if (other.moveNext()) {
        return -1;
      } else {
        return 0;
      }
    }
  }
}