private Revision getReferencedRevision ( final int articleID , final int revisionIndex , final String fullRevisions , final String revCounters ) throws WikiApiException { try { int fullRevPK = - 1 ; int limit = 1 ; String fullRev = null ; int revA = - 1 , revB = - 1 ; int lengthFR = 0 ; int lengthRC = 0 ; int index ; int max = fullRevisions . length ( ) ; while ( lengthFR < max && revB < revisionIndex ) { // Read fullRevisionPK (as string) index = fullRevisions . indexOf ( ' ' , lengthFR ) ; if ( index == - 1 ) { index = max ; } fullRev = fullRevisions . substring ( lengthFR , index ) ; lengthFR = index + 1 ; // Read start revision counter index = revCounters . indexOf ( ' ' , lengthRC ) ; revA = Integer . parseInt ( revCounters . substring ( lengthRC , index ) ) ; lengthRC = index + 1 ; // Read end revision counter index = revCounters . indexOf ( ' ' , lengthRC ) ; if ( index == - 1 ) { index = revCounters . length ( ) ; } revB = Integer . parseInt ( revCounters . substring ( lengthRC , index ) ) ; lengthRC = index + 1 ; } if ( revisionIndex > revB ) { throw new WikiPageNotFoundException ( "The article with the ID " + articleID + " has no revision number " + revisionIndex ) ; } fullRevPK = Integer . parseInt ( fullRev ) ; limit = ( revisionIndex - revA ) + 1 ; // Build the revision return buildRevisionMetaData ( fullRevPK , limit ) ; } catch ( WikiPageNotFoundException e ) { throw e ; } catch ( Exception e ) { throw new WikiApiException ( e ) ; } }
This method identifies the correct full revision and retrieves the reference revision .