@Test public void secondAncestorOfPropertyShouldBeParentOfParentNode() throws Exception { assertThat(newPropertyOnModifiedNode.getAncestor(2), is((Item)newPropertyOnModifiedNode)); assertThat(modifiedPropertyOnModifiedNode.getAncestor(2), is((Item)modifiedPropertyOnModifiedNode)); assertThat(unmodifiedPropertyOnModifiedNode.getAncestor(2), is((Item)unmodifiedPropertyOnModifiedNode)); }
@Override public Item getAncestor( int depth ) throws RepositoryException { checkSession(); if (depth < 0) { throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth)); } depth = getDepth() - depth; if (depth < 0) { throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth)); } Item ancestor = this; while (--depth >= 0) { ancestor = ancestor.getParent(); } return ancestor; }
AbstractJcrItem implements Item, Namespaced { @Override public Item getAncestor( int depth ) throws RepositoryException { checkSession(); if (depth < 0) { throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth)); } depth = getDepth() - depth; if (depth < 0) { throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth)); } Item ancestor = this; while (--depth >= 0) { ancestor = ancestor.getParent(); } return ancestor; } }
AbstractJcrItem implements Item, Namespaced { @Override public Item getAncestor( int depth ) throws RepositoryException { checkSession(); if (depth < 0) { throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth)); } depth = getDepth() - depth; if (depth < 0) { throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth)); } Item ancestor = this; while (--depth >= 0) { ancestor = ancestor.getParent(); } return ancestor; } protected  AbstractJcrItem( JcrSession session ); }
AbstractJcrItem implements Item, Namespaced { @Override public Item getAncestor( int depth ) throws RepositoryException { checkSession(); if (depth < 0) { throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth)); } depth = getDepth() - depth; if (depth < 0) { throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth)); } Item ancestor = this; while (--depth >= 0) { ancestor = ancestor.getParent(); } return ancestor; } protected  AbstractJcrItem( JcrSession session ); @Override Item getAncestor( int depth ); @Override int getDepth(); @Override abstract AbstractJcrNode getParent(); }
AbstractJcrItem implements Item, Namespaced { @Override public Item getAncestor( int depth ) throws RepositoryException { checkSession(); if (depth < 0) { throw new ItemNotFoundException(JcrI18n.noNegativeDepth.text(depth)); } depth = getDepth() - depth; if (depth < 0) { throw new ItemNotFoundException(JcrI18n.tooDeep.text(depth)); } Item ancestor = this; while (--depth >= 0) { ancestor = ancestor.getParent(); } return ancestor; } protected  AbstractJcrItem( JcrSession session ); @Override Item getAncestor( int depth ); @Override int getDepth(); @Override abstract AbstractJcrNode getParent();  }