private boolean validateADS ( final ADTNode < ADTState < I , O > , I , O > oldADS , final ADTNode < ADTState < I , O > , I , O > newADS , final Set < ADTState < I , O > > cutout ) { final Set < ADTNode < ADTState < I , O > , I , O > > oldNodes ; if ( ADTUtil . isResetNode ( oldADS ) ) { oldNodes = ADTUtil . collectResetNodes ( this . adt . getRoot ( ) ) ; } else { oldNodes = ADTUtil . collectADSNodes ( this . adt . getRoot ( ) ) ; } if ( ! oldNodes . contains ( oldADS ) ) { throw new IllegalArgumentException ( "Subtree to replace does not exist" ) ; } final Set < ADTNode < ADTState < I , O > , I , O > > oldFinalNodes = ADTUtil . collectLeaves ( oldADS ) ; final Set < ADTNode < ADTState < I , O > , I , O > > newFinalNodes = ADTUtil . collectLeaves ( newADS ) ; final Set < ADTState < I , O > > oldFinalStates = oldFinalNodes . stream ( ) . map ( ADTNode :: getHypothesisState ) . collect ( Collectors . toSet ( ) ) ; final Set < ADTState < I , O > > newFinalStates = newFinalNodes . stream ( ) . map ( ADTNode :: getHypothesisState ) . collect ( Collectors . toSet ( ) ) ; newFinalStates . addAll ( cutout ) ; if ( ! oldFinalStates . equals ( newFinalStates ) ) { throw new IllegalArgumentException ( "New ADS does not cover all old nodes" ) ; } final Word < I > parentInputTrace = ADTUtil . buildTraceForNode ( oldADS ) . getFirst ( ) ; final Map < ADTState < I , O > , Pair < Word < I > , Word < O > > > traces = newFinalNodes . stream ( ) . collect ( Collectors . toMap ( ADTNode :: getHypothesisState , ADTUtil :: buildTraceForNode ) ) ; for ( final Map . Entry < ADTState < I , O > , Pair < Word < I > , Word < O > > > entry : traces . entrySet ( ) ) { final Word < I > accessSequence = entry . getKey ( ) . getAccessSequence ( ) ; final Word < I > prefix = accessSequence . concat ( parentInputTrace ) ; final Word < I > input = entry . getValue ( ) . getFirst ( ) ; final Word < O > output = entry . getValue ( ) . getSecond ( ) ; if ( ! this . hypothesis . computeSuffixOutput ( prefix , input ) . equals ( output ) ) { throw new IllegalArgumentException ( "Output of new ADS does not match hypothesis" ) ; } } return true ; }
Validate the well - definedness of an ADT replacement i . e . both ADTs cover the same set of hypothesis states and the output behavior described in the replacement matches the hypothesis output .