@Test public void shouldDelegateToParentForAncestorOfDegreeGreaterThanOne() { parent = mock(Path.class); when(parent.getAncestor(anyInt())).thenReturn(null); path = new ChildPath(parent, segment("d")); for (int i = 2; i != 10; ++i) { path.getAncestor(i); verify(parent).getAncestor(i - 1); } }
@Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; if (degree == 1) return parent; return parent.getAncestor(degree - 1); }
ChildPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; if (degree == 1) return parent; return parent.getAncestor(degree - 1); } }
ChildPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; if (degree == 1) return parent; return parent.getAncestor(degree - 1); } ChildPath( Path parent,
                      Path.Segment child ); }
ChildPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; if (degree == 1) return parent; return parent.getAncestor(degree - 1); } ChildPath( Path parent,
                      Path.Segment child ); @Override Path getAncestor( int degree ); @Override Segment getLastSegment(); @Override Path getParent(); @Override Segment getSegment( int index ); @Override List<Segment> getSegmentsList(); @Override boolean hasSameAncestor( Path that ); @Override boolean isAbsolute(); @Override boolean isAtOrBelow( Path other ); @Override boolean isDescendantOf( Path ancestor ); @Override boolean isNormalized(); @Override boolean isRoot(); @Override @SuppressWarnings( "synthetic-access" ) Iterator<Segment> iterator(); @Override int size(); @Override Path subpath( int beginIndex,
                         int endIndex ); }
ChildPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; if (degree == 1) return parent; return parent.getAncestor(degree - 1); } ChildPath( Path parent,
                      Path.Segment child ); @Override Path getAncestor( int degree ); @Override Segment getLastSegment(); @Override Path getParent(); @Override Segment getSegment( int index ); @Override List<Segment> getSegmentsList(); @Override boolean hasSameAncestor( Path that ); @Override boolean isAbsolute(); @Override boolean isAtOrBelow( Path other ); @Override boolean isDescendantOf( Path ancestor ); @Override boolean isNormalized(); @Override boolean isRoot(); @Override @SuppressWarnings( "synthetic-access" ) Iterator<Segment> iterator(); @Override int size(); @Override Path subpath( int beginIndex,
                         int endIndex );  }