@Test public void shouldReturnNthDegreeAncestor() { assertThat(path.getAncestor(1), is(pathFactory.create("/mode:a/mode:b"))); assertThat(path.getAncestor(2), is(pathFactory.create("/mode:a"))); assertThat(path.getAncestor(3), is(ROOT)); }
@Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; int endIndex = this.segments.size() - degree; if (endIndex == 0) return this.isAbsolute() ? RootPath.INSTANCE : null; if (endIndex < 0) { String msg = GraphI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree)); throw new InvalidPathException(msg); } return subpath(0, endIndex); }
BasicPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; int endIndex = this.segments.size() - degree; if (endIndex == 0) return this.isAbsolute() ? RootPath.INSTANCE : null; if (endIndex < 0) { String msg = GraphI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree)); throw new InvalidPathException(msg); } return subpath(0, endIndex); } }
BasicPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; int endIndex = this.segments.size() - degree; if (endIndex == 0) return this.isAbsolute() ? RootPath.INSTANCE : null; if (endIndex < 0) { String msg = GraphI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree)); throw new InvalidPathException(msg); } return subpath(0, endIndex); } BasicPath( List<Segment> segments,
                      boolean absolute ); }
BasicPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; int endIndex = this.segments.size() - degree; if (endIndex == 0) return this.isAbsolute() ? RootPath.INSTANCE : null; if (endIndex < 0) { String msg = GraphI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree)); throw new InvalidPathException(msg); } return subpath(0, endIndex); } BasicPath( List<Segment> segments,
                      boolean absolute ); @Override Path getAncestor( int degree ); @Override List<Segment> getSegmentsList(); @Override boolean isAbsolute(); @Override boolean isNormalized(); @Override boolean isRoot(); @Override int size(); }
BasicPath extends AbstractPath { @Override public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; int endIndex = this.segments.size() - degree; if (endIndex == 0) return this.isAbsolute() ? RootPath.INSTANCE : null; if (endIndex < 0) { String msg = GraphI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree)); throw new InvalidPathException(msg); } return subpath(0, endIndex); } BasicPath( List<Segment> segments,
                      boolean absolute ); @Override Path getAncestor( int degree ); @Override List<Segment> getSegmentsList(); @Override boolean isAbsolute(); @Override boolean isNormalized(); @Override boolean isRoot(); @Override int size(); static final Path EMPTY_RELATIVE; static final Path SELF_PATH; static final Path PARENT_PATH; }