Esempio n. 1
0
  /**
   * Returns the index of the specified child in this node's child array. If the specified node is
   * not a child of this node, returns <code>-1</code>. This method performs a linear search and is
   * O(n) where n is the number of children.
   *
   * @param aChild the TreeNode to search for among this node's children
   * @exception IllegalArgumentException if <code>aChild</code> is null
   * @return an int giving the index of the node in this node's child array, or <code>-1</code> if
   *     the specified node is a not a child of this node
   */
  public int getIndex(TreeNode aChild) {
    if (aChild == null) {
      throw new IllegalArgumentException("argument is null");
    }

    if (!isNodeChild(aChild)) {
      return -1;
    }
    return children.indexOf(aChild); // linear search
  }