/**
  * Check whether two Spans in the same document are ordered with possible overlap.
  *
  * @return true iff spans1 starts before spans2 or the spans start at the same position, and
  *     spans1 ends before spans2.
  */
 static boolean positionsOrdered(Spans spans1, Spans spans2) {
   assert spans1.docID() == spans2.docID()
       : "doc1 " + spans1.docID() + " != doc2 " + spans2.docID();
   int start1 = spans1.startPosition();
   int start2 = spans2.startPosition();
   return (start1 == start2) ? (spans1.endPosition() < spans2.endPosition()) : (start1 < start2);
 }
 private void adjustLength() {
   if (spanLength != -1) {
     totalSpanLength -= spanLength; // subtract old, possibly from a previous doc
   }
   assert in.startPosition() != NO_MORE_POSITIONS;
   spanLength = endPosition() - startPosition();
   assert spanLength >= 0;
   totalSpanLength += spanLength; // add new
 }
 @Override
 public int startPosition() {
   return in.startPosition();
 }