protected CSNodeWrapper findExistingNode ( final CSNodeWrapper parent , final Node childNode , final List < CSNodeWrapper > entityChildrenNodes ) { CSNodeWrapper foundNodeEntity = null ; if ( entityChildrenNodes != null && ! entityChildrenNodes . isEmpty ( ) ) { for ( final CSNodeWrapper nodeEntity : entityChildrenNodes ) { // ignore it if the parent doesn't match otherwise keep looking to see if we can find a better match if ( ! doesParentMatch ( parent , nodeEntity . getParent ( ) ) ) { continue ; } if ( childNode instanceof Comment ) { // Comments are handled differently to try and get the exact comment better, since its common for multiple comments // to be on the same level if ( doesCommentMatch ( ( Comment ) childNode , nodeEntity , foundNodeEntity != null ) ) { foundNodeEntity = nodeEntity ; } } else if ( childNode instanceof Level ) { // Since levels might have other possible titles that are in the title threshold, // we need to keep looping to see if we can find something better if ( doesLevelMatch ( ( Level ) childNode , nodeEntity , foundNodeEntity != null ) ) { foundNodeEntity = nodeEntity ; } // stop looking if the title matches otherwise keep looking to see if we can find a better match if ( parent != null && foundNodeEntity != null && foundNodeEntity . getTitle ( ) . equals ( ( ( Level ) childNode ) . getTitle ( ) ) ) { break ; } } else { if ( childNode instanceof SpecTopic && doesTopicMatch ( ( SpecTopic ) childNode , nodeEntity , foundNodeEntity != null ) ) { foundNodeEntity = nodeEntity ; } else if ( childNode instanceof CommonContent && doesCommonContentMatch ( ( CommonContent ) childNode , nodeEntity , foundNodeEntity != null ) ) { foundNodeEntity = nodeEntity ; } else if ( childNode instanceof KeyValueNode && doesMetaDataMatch ( ( KeyValueNode < ? > ) childNode , nodeEntity ) ) { foundNodeEntity = nodeEntity ; } else if ( childNode instanceof File && doesFileMatch ( ( File ) childNode , nodeEntity ) ) { foundNodeEntity = nodeEntity ; } } } } return foundNodeEntity ; }
Finds the existing Entity Node that matches a ContentSpec node .