/** * Determines and retrieves data related to the first confluence node (defined as a node with two * or more incoming transitions) of a _transition path corresponding to a given String from a * given node. * * @param originNode the MDAGNode from which the _transition path corresponding to str starts from * @param str a String corresponding to a _transition path in the MDAG * @return a HashMap of Strings to Objects containing: - an int denoting the length of the path to * the first confluence node in the _transition path of interest - the MDAGNode which is the * first confluence node in the _transition path of interest (or null if one does not exist) */ private HashMap<String, Object> getTransitionPathFirstConfluenceNodeData( MDAGNode originNode, String str) { int currentIndex = 0; int charCount = str.length(); MDAGNode currentNode = originNode; // Loop thorugh the characters in str, sequentially using them to _transition through the MDAG // in search of // (and breaking upon reaching) the first node that is the target of two or more transitions. // The loop is // also broken from if the currently processing node doesn't have a _transition labeled with the // currently processing char. for (; currentIndex < charCount; currentIndex++) { char currentChar = str.charAt(currentIndex); currentNode = (currentNode.hasOutgoingTransition(currentChar) ? currentNode.transition(currentChar) : null); if (currentNode == null || currentNode.isConfluenceNode()) break; } ///// boolean noConfluenceNode = (currentNode == originNode || currentIndex == charCount); // Create a HashMap containing the index of the last char in the substring corresponding // to the transitoin path to the confluence node, as well as the actual confluence node HashMap<String, Object> confluenceNodeDataHashMap = new HashMap<String, Object>(2); confluenceNodeDataHashMap.put( "toConfluenceNodeTransitionCharIndex", (noConfluenceNode ? null : currentIndex)); confluenceNodeDataHashMap.put("confluenceNode", noConfluenceNode ? null : currentNode); ///// return confluenceNodeDataHashMap; }