code: private static boolean peek(ListIterator<Segment> segments, SegmentKind... kinds) {
      int start = segments.nextIndex();
      boolean success = false;
      for (SegmentKind kind : kinds) {
        if (!segments.hasNext() || segments.next().kind() != kind) {
          success = false;
          break;
        }
      }
      if (success) {
        return true;
      }
      restore(segments, start);
      return false;
    }
docs: the list iterator in its state.