Пример #1
0
  /**
   * Retrieves Strings corresponding to all valid _transition paths from a given node that satisfy a
   * given condition.
   *
   * @param strHashSet a HashSet of Strings to contain all those in the MDAG satisfying {@code
   *     searchCondition} with {@code conditionString}
   * @param searchCondition the SearchCondition enum field describing the type of relationship that
   *     Strings contained in the MDAG must have with {@code conditionString} in order to be
   *     included in the result set
   * @param searchConditionString the String that all Strings in the MDAG must be related with in
   *     the fashion denoted by {@code searchCondition} in order to be included in the result set
   * @param prefixString the String corresponding to the currently traversed _transition path
   * @param node an int denoting the starting index of a SimpleMDAGNode's _transition set in
   *     mdagDataArray
   */
  private void getStrings(
      HashSet<String> strHashSet,
      SearchCondition searchCondition,
      String searchConditionString,
      String prefixString,
      SimpleMDAGNode node) {
    int transitionSetBegin = node.getTransitionSetBeginIndex();
    int onePastTransitionSetEnd = transitionSetBegin + node.getOutgoingTransitionSetSize();

    // Traverse all the valid _transition paths beginning from each _transition in
    // transitionTreeMap, inserting the
    // corresponding Strings in to strHashSet that have the relationship with conditionString
    // denoted by searchCondition
    for (int i = transitionSetBegin; i < onePastTransitionSetEnd; i++) {
      SimpleMDAGNode currentNode = mdagDataArray[i];
      String newPrefixString = prefixString + currentNode.getLetter();

      if (currentNode.isAcceptNode()
          && searchCondition.satisfiesCondition(newPrefixString, searchConditionString))
        strHashSet.add(newPrefixString);

      // Recursively call this to traverse all the valid _transition paths from currentNode
      getStrings(strHashSet, searchCondition, searchConditionString, newPrefixString, currentNode);
    }
    /////
  }
Пример #2
0
  /**
   * 递归创建节点<br>
   *
   * @param current 当前简易节点
   * @param fromIndex 起点下标
   * @param toNodeArray 终点数组
   * @param fromNodeArray 起点数组,它们两个按照下标一一对应
   */
  private void createMDAGNode(
      SimpleMDAGNode current, int fromIndex, MDAGNode[] toNodeArray, MDAGNode[] fromNodeArray) {
    MDAGNode from = (fromIndex == -1 ? sourceNode : toNodeArray[fromIndex]);
    int transitionSetBegin = current.getTransitionSetBeginIndex();
    int onePastTransitionSetEnd = transitionSetBegin + current.getOutgoingTransitionSetSize();

    for (int i = transitionSetBegin; i < onePastTransitionSetEnd; i++) {
      SimpleMDAGNode targetNode = mdagDataArray[i];
      if (toNodeArray[i] != null) {
        fromNodeArray[fromIndex].addOutgoingTransition(current.getLetter(), fromNodeArray[i]);
        toNodeArray[fromIndex] = fromNodeArray[i];
        continue;
      }
      toNodeArray[i] =
          from.addOutgoingTransition(targetNode.getLetter(), targetNode.isAcceptNode());
      fromNodeArray[i] = from;
      createMDAGNode(targetNode, i, toNodeArray, fromNodeArray);
    }
  }