private void parseTree ( List < Block > sourceBlocks ) { Block matchStartBlock = null ; int count = 0 ; Block mappingCursor = this . mappingTree . getChildren ( ) . get ( 0 ) ; Block sourceBlock = sourceBlocks . get ( 0 ) ; while ( sourceBlock != null ) { while ( mappingCursor != null ) { if ( blockEquals ( sourceBlock , mappingCursor ) ) { if ( matchStartBlock == null ) { matchStartBlock = sourceBlock ; } count ++ ; mappingCursor = mappingCursor . getChildren ( ) . get ( 0 ) ; // If we reach the Image Block then we've found a match! if ( mappingCursor instanceof ImageBlock ) { // Replace the first source block with the image block and remove all other blocks... for ( int i = 0 ; i < count - 1 ; i ++ ) { matchStartBlock . getParent ( ) . removeBlock ( matchStartBlock . getNextSibling ( ) ) ; } sourceBlock = mappingCursor . clone ( ) ; matchStartBlock . getParent ( ) . replaceChild ( sourceBlock , matchStartBlock ) ; mappingCursor = null ; matchStartBlock = null ; count = 0 ; } else { // Look for next block match break ; } } else { mappingCursor = mappingCursor . getNextSibling ( ) ; } } // Look for a match in children of the source block List < Block > filteredSourceBlocks = this . filter . filter ( sourceBlock . getChildren ( ) ) ; if ( ! filteredSourceBlocks . isEmpty ( ) ) { parseTree ( filteredSourceBlocks ) ; } else if ( mappingCursor == null ) { // No match has been found, reset state variables mappingCursor = this . mappingTree . getChildren ( ) . get ( 0 ) ; count = 0 ; matchStartBlock = null ; } sourceBlock = this . filter . getNextSibling ( sourceBlock ) ; } }
Parse a list of blocks and replace suite of Blocks matching the icon mapping definitions by image blocks .