Example #1
0
  /**
   * Finds first element in the tree that satisfy specified condition.
   *
   * @param condition
   * @param isRecursive
   * @return First TagNode found, or null if no such elements.
   */
  private TagNode findElement(ITagNodeCondition condition, boolean isRecursive) {
    if (condition == null) {
      return null;
    }

    for (int i = 0; i < children.size(); i++) {
      Object item = children.get(i);
      if (item instanceof TagNode) {
        TagNode currNode = (TagNode) item;
        if (condition.satisfy(currNode)) {
          return currNode;
        } else if (isRecursive) {
          TagNode inner = currNode.findElement(condition, isRecursive);
          if (inner != null) {
            return inner;
          }
        }
      }
    }

    return null;
  }
Example #2
0
  /**
   * Get all elements in the tree that satisfy specified condition.
   *
   * @param condition
   * @param isRecursive
   * @return List of TagNode instances with specified name.
   */
  private List getElementList(ITagNodeCondition condition, boolean isRecursive) {
    List result = new LinkedList();
    if (condition == null) {
      return result;
    }

    for (int i = 0; i < children.size(); i++) {
      Object item = children.get(i);
      if (item instanceof TagNode) {
        TagNode currNode = (TagNode) item;
        if (condition.satisfy(currNode)) {
          result.add(currNode);
        }
        if (isRecursive) {
          List innerList = currNode.getElementList(condition, isRecursive);
          if (innerList != null && innerList.size() > 0) {
            result.addAll(innerList);
          }
        }
      }
    }

    return result;
  }