@@ -414,8 +414,8 @@ public void checkReferences()
414414 break ;
415415 }
416416 }
417- checkReadingOrder (tocLinks , - 1 , - 1 );
418- checkReadingOrder (overlayLinks , - 1 , - 1 );
417+ checkReadingOrder (tocLinks );
418+ checkReadingOrder (overlayLinks );
419419 }
420420
421421 private void checkReference (URLReference reference )
@@ -665,58 +665,30 @@ private void checkRegionBasedNav(URLReference ref)
665665 }
666666 }
667667
668- private void checkReadingOrder (Queue <URLReference > references , int lastSpinePosition ,
669- int lastAnchorPosition )
668+ private void checkReadingOrder (Queue <URLReference > references )
670669 {
671- // de-queue
672- URLReference ref = references .poll ();
673- if (ref == null ) return ;
674-
675- Preconditions .checkArgument (ref .type == Type .NAV_PAGELIST_LINK || ref .type == Type .NAV_TOC_LINK
676- || ref .type == Type .OVERLAY_TEXT_LINK );
677- Resource res = resources .get (ref .targetDoc );
678-
679- // abort early if the link target is not a spine item (checked elsewhere)
680- if (res == null || !res .hasItem () || !res .getItem ().isInSpine ()) return ;
681-
682- // check that the link is in spine order
683- int targetSpinePosition = res .getItem ().getSpinePosition ();
684- if (targetSpinePosition < lastSpinePosition )
670+ int lastSpinePosition = -1 ;
671+ int lastAnchorPosition = -1 ;
672+ while (!references .isEmpty ())
685673 {
686- String orderContext = LocalizedMessages .getInstance (locale ).getSuggestion (MessageId .NAV_011 ,
687- "spine" );
688-
689- if (ref .type == Type .OVERLAY_TEXT_LINK )
690- {
691- report .message (MessageId .MED_015 , ref .location , container .relativize (ref .url ),
692- orderContext );
693- }
694- else
695- {
696- report .message (MessageId .NAV_011 , ref .location ,
697- (ref .type == Type .NAV_TOC_LINK ) ? "toc" : "page-list" , container .relativize (ref .url ),
698- orderContext );
699- }
700- lastSpinePosition = targetSpinePosition ;
701- lastAnchorPosition = -1 ;
702- }
703- else
704- {
705-
706- // if new spine item, reset last positions
707- if (targetSpinePosition > lastSpinePosition )
674+ URLReference ref = references .poll ();
675+ Preconditions
676+ .checkArgument (ref .type == Type .NAV_PAGELIST_LINK || ref .type == Type .NAV_TOC_LINK
677+ || ref .type == Type .OVERLAY_TEXT_LINK );
678+ Resource res = resources .get (ref .targetDoc );
679+ // abort early if the link target is not a spine item (checked elsewhere)
680+ if (res == null || !res .hasItem () || !res .getItem ().isInSpine ())
708681 {
709- lastSpinePosition = targetSpinePosition ;
710- lastAnchorPosition = -1 ;
682+ continue ;
711683 }
712684
713- // check that the fragment is in document order
714- URLFragment fragment = URLFragment .parse (ref .url , res .getMimeType ());
715- int targetAnchorPosition = res .getIDPosition (fragment .getId ());
716- if (targetAnchorPosition < lastAnchorPosition )
685+ // check that the link is in spine order
686+ int targetSpinePosition = res .getItem ().getSpinePosition ();
687+ if (targetSpinePosition < lastSpinePosition )
717688 {
718689 String orderContext = LocalizedMessages .getInstance (locale ).getSuggestion (MessageId .NAV_011 ,
719- "document" );
690+ "spine" );
691+
720692 if (ref .type == Type .OVERLAY_TEXT_LINK )
721693 {
722694 report .message (MessageId .MED_015 , ref .location , container .relativize (ref .url ),
@@ -728,9 +700,43 @@ private void checkReadingOrder(Queue<URLReference> references, int lastSpinePosi
728700 (ref .type == Type .NAV_TOC_LINK ) ? "toc" : "page-list" , container .relativize (ref .url ),
729701 orderContext );
730702 }
703+ lastSpinePosition = targetSpinePosition ;
704+ lastAnchorPosition = -1 ;
705+ }
706+ else
707+ {
708+
709+ // if new spine item, reset last positions
710+ if (targetSpinePosition > lastSpinePosition )
711+ {
712+ lastSpinePosition = targetSpinePosition ;
713+ lastAnchorPosition = -1 ;
714+ }
715+
716+ // check that the fragment is in document order
717+ URLFragment fragment = URLFragment .parse (ref .url , res .getMimeType ());
718+ int targetAnchorPosition = res .getIDPosition (fragment .getId ());
719+ if (targetAnchorPosition < lastAnchorPosition )
720+ {
721+ String orderContext = LocalizedMessages .getInstance (locale ).getSuggestion (
722+ MessageId .NAV_011 ,
723+ "document" );
724+ if (ref .type == Type .OVERLAY_TEXT_LINK )
725+ {
726+ report .message (MessageId .MED_015 , ref .location , container .relativize (ref .url ),
727+ orderContext );
728+ }
729+ else
730+ {
731+ report .message (MessageId .NAV_011 , ref .location ,
732+ (ref .type == Type .NAV_TOC_LINK ) ? "toc" : "page-list" ,
733+ container .relativize (ref .url ),
734+ orderContext );
735+ }
736+ }
737+ lastAnchorPosition = targetAnchorPosition ;
731738 }
732- lastAnchorPosition = targetAnchorPosition ;
733739 }
734- checkReadingOrder ( references , lastSpinePosition , lastAnchorPosition );
740+
735741 }
736742}
0 commit comments