public synchronized boolean validate ( java . io . PrintStream printStream ) throws ObjectManagerException { if ( Tracing . isAnyTracingEnabled ( ) && trace . isEntryEnabled ( ) ) trace . entry ( this , cclass , "validate" , new Object [ ] { printStream } ) ; boolean valid = true ; Link tailLink = null ; if ( tail != null ) { tailLink = ( Link ) tail . getManagedObject ( ) ; if ( tailLink . next != null ) { printStream . println ( "tail link.next=" + tailLink . next + " not null" ) ; valid = false ; } } // Forward scan. long numberOfLinks = 0 ; Token nextToken = head ; Link nextLink = null ; while ( nextToken != null ) { numberOfLinks ++ ; nextLink = ( Link ) ( nextToken . getManagedObject ( ) ) ; nextToken = nextLink . next ; } // while (... if ( numberOfLinks != size ) { printStream . println ( "counted=" + numberOfLinks + " not equal to size=" + size ) ; valid = false ; } // if (numberOfLinks != size). if ( nextLink != tailLink ) { printStream . println ( "final link=" + nextLink + "not equal tail=" + tailLink ) ; valid = false ; } // if (numberOfLinks != size). if ( Tracing . isAnyTracingEnabled ( ) && trace . isEntryEnabled ( ) ) trace . exit ( this , cclass , "validate" , new Object [ ] { new Boolean ( valid ) } ) ; return valid ; }
Check that the head leads to the tail in both the forwards and backwards directions . Check that the number of messages in between matches the size .