org.jdom2.Element.isAncestor()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(1.5k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中org.jdom2.Element.isAncestor()方法的一些代码示例,展示了Element.isAncestor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.isAncestor()方法的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
方法名:isAncestor

Element.isAncestor介绍

[英]Determines if this element is the ancestor of another element.
[中]确定此元素是否是另一个元素的祖先。

代码示例

代码示例来源:origin: org.jdom/jdom

private final void checkPreConditions(final Content child, final int index,
    final boolean replace) {
  if (child == null) {
    throw new NullPointerException("Cannot add null object");
  }
  checkIndex(index, replace);
  if (child.getParent() != null) {
    // the content to be added already has a parent.
    final Parent p = child.getParent();
    if (p instanceof Document) {
      throw new IllegalAddException((Element) child,
          "The Content already has an existing parent document");
    }
    throw new IllegalAddException(
        "The Content already has an existing parent \"" +
            ((Element) p).getQualifiedName() + "\"");
  }
  if (child == parent) {
    throw new IllegalAddException(
        "The Element cannot be added to itself");
  }
  // Detect if we have <a><b><c/></b></a> and c.add(a)
  if ((parent instanceof Element && child instanceof Element) &&
      ((Element) child).isAncestor((Element) parent)) {
    throw new IllegalAddException(
        "The Element cannot be added as a descendent of itself");
  }
}

代码示例来源:origin: org.codehaus.plexus/plexus-component-metadata

/**
 * @see org.jdom2.Element#isAncestor(org.jdom2.Element)
 * @param element {@link Element}.
 * @return true/false.
 */
public boolean isAncestor( Element element )
{
  return element.isAncestor( element );
}

相关文章

微信公众号

最新文章

更多