Package org.modeshape.jcr.value

Examples of org.modeshape.jcr.value.Path

This class simplifies working with paths and using a Path is often more efficient that processing and manipulating the equivalent String. This class can easily {@link #iterator() iterate} over the segments, returnthe {@link #size() number of segments}, {@link #compareTo(Path) compare} with other paths, {@link #resolve(Path) resolve}relative paths, return the {@link #getParent() ancestor (or parent)}, determine whether one path is an {@link #isAncestorOf(Path) ancestor} or {@link #isDescendantOf(Path) decendent} of another path, and{@link #getCommonAncestor(Path) finding a common ancestor}.


        assertThat(ROOT.hasSameAncestor(ROOT), is(true));
    }

    @Test
    public void shouldConsiderTwoNotRootSiblingNodesToHaveSameAncestor() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/y/c");
        assertThat(path1.hasSameAncestor(path2), is(true));

        path1 = pathFactory.create("/a/z");
        path2 = pathFactory.create("/a/c");
        assertThat(path1.hasSameAncestor(path2), is(true));
View Full Code Here


        assertThat(path1.hasSameAncestor(path2), is(true));
    }

    @Test
    public void shouldNotConsiderTwoNonSiblingNodesToHaveSameAncestor() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/x/c");
        assertThat(path1.hasSameAncestor(path2), is(false));

        path1 = pathFactory.create("/a/z");
        path2 = pathFactory.create("/b/c");
        assertThat(path1.hasSameAncestor(path2), is(false));
View Full Code Here

        assertThat(path.isAtOrBelow(path), is(true));
    }

    @Test
    public void shouldConsiderAncestorToBeAtOrAboveTheDecendant() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
        for (int i = 1; i < path1.size(); ++i) {
            assertThat(path1.getAncestor(i).isAtOrAbove(path1), is(true));
        }
        for (int i = 1; i < path2.size(); ++i) {
            assertThat(path2.getAncestor(i).isAtOrAbove(path2), is(true));
        }
        for (int i = 1; i < path3.size(); ++i) {
            assertThat(path3.getAncestor(i).isAtOrAbove(path3), is(true));
        }
        for (int i = 1; i < path4.size(); ++i) {
            assertThat(path4.getAncestor(i).isAtOrAbove(path4), is(true));
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldConsiderDecendantToBeAtOrBelowTheAncestor() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
        for (int i = 1; i < path1.size(); ++i) {
            assertThat(path1.isAtOrBelow(path1.getAncestor(i)), is(true));
        }
        for (int i = 1; i < path2.size(); ++i) {
            assertThat(path2.isAtOrBelow(path2.getAncestor(i)), is(true));
        }
        for (int i = 1; i < path3.size(); ++i) {
            assertThat(path3.isAtOrBelow(path3.getAncestor(i)), is(true));
        }
        for (int i = 1; i < path4.size(); ++i) {
            assertThat(path4.isAtOrBelow(path4.getAncestor(i)), is(true));
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldNotConsiderAncestorToBeAtOrBelowTheDecendant() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
        for (int i = 1; i < path1.size(); ++i) {
            assertThat(path1.getAncestor(i).isAtOrBelow(path1), is(false));
        }
        for (int i = 1; i < path2.size(); ++i) {
            assertThat(path2.getAncestor(i).isAtOrBelow(path2), is(false));
        }
        for (int i = 1; i < path3.size(); ++i) {
            assertThat(path3.getAncestor(i).isAtOrBelow(path3), is(false));
        }
        for (int i = 1; i < path4.size(); ++i) {
            assertThat(path4.getAncestor(i).isAtOrBelow(path4), is(false));
        }
    }
View Full Code Here

        }
    }

    @Test
    public void shouldNotConsiderDecendantToBeAtOrAboveTheAncestor() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z");
        for (int i = 1; i < path1.size(); ++i) {
            assertThat(path1.isAtOrAbove(path1.getAncestor(i)), is(false));
        }
        for (int i = 1; i < path2.size(); ++i) {
            assertThat(path2.isAtOrAbove(path2.getAncestor(i)), is(false));
        }
        for (int i = 1; i < path3.size(); ++i) {
            assertThat(path3.isAtOrAbove(path3.getAncestor(i)), is(false));
        }
        for (int i = 1; i < path4.size(); ++i) {
            assertThat(path4.isAtOrAbove(path4.getAncestor(i)), is(false));
        }
    }
View Full Code Here

        assertThat(ROOT.getLastSegment(), is(nullValue()));
    }

    @Test
    public void shouldReturnLastSegmentOfNonRootPath() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x");
        assertThat(path1.getLastSegment().getName().getLocalName(), is("z"));
        assertThat(path2.getLastSegment().getName().getLocalName(), is("c"));
        assertThat(path3.getLastSegment().getName().getLocalName(), is("c"));
        assertThat(path4.getLastSegment().getName().getLocalName(), is("x"));
    }
View Full Code Here

                if ("{".equals(text)) return "\\{";
                if ("}".equals(text)) return "\\}";
                return text;
            }
        };
        Path path = pathFactory.create("a/b/c");
        assertThat(path.getString(registry), is("a/b/c"));
        assertThat(path.getString(registry, encoder), is("a/b/c"));
        assertThat(path.getString(registry, encoder, delimEncoder), is("a\\/b\\/c"));

        path = pathFactory.create("/a/b/c");
        assertThat(path.getString(registry), is("/a/b/c"));
        assertThat(path.getString(registry, encoder), is("/a/b/c"));
        assertThat(path.getString(registry, encoder, delimEncoder), is("\\/a\\/b\\/c"));

        path = pathFactory.create("/mode:a/b/c");
        assertThat(path.getString(encoder), is("/{" + encoder.encode(ModeShapeLexicon.Namespace.URI) + "}a/{}b/{}c"));
        assertThat(path.getString(null, encoder, delimEncoder), is("\\/mode:a\\/\\{\\}b\\/\\{\\}c"));
        assertThat(path.getString(registry), is("/mode:a/b/c"));
        assertThat(path.getString(registry, encoder), is("/mode:a/b/c"));
        assertThat(path.getString(registry, encoder, delimEncoder), is("\\/mode\\:a\\/b\\/c"));
    }
View Full Code Here

    @Override
    public Path getCommonAncestor( Path that ) {
        CheckArg.isNotNull(that, "that");
        if (that.isRoot()) return that;
        Path normalizedPath = this.getNormalizedPath();
        int lastIndex = 0;
        Iterator<Segment> thisIter = normalizedPath.iterator();
        Iterator<Segment> thatIter = that.getNormalizedPath().iterator();
        while (thisIter.hasNext() && thatIter.hasNext()) {
            Segment thisSeg = thisIter.next();
            Segment thatSeg = thatIter.next();
            if (thisSeg.equals(thatSeg)) {
                ++lastIndex;
            } else {
                break;
            }
        }
        if (lastIndex == 0) return RootPath.INSTANCE;
        return normalizedPath.subpath(0, lastIndex);
    }
View Full Code Here

        if (this == other) return true;
        if (other.isRoot()) return true;
        if (other.size() > this.size()) return false;

        // Find this path's ancestor that is of the same size ...
        Path thisPath = this.getAncestor(this.size() - other.size());
        Path thatPath = other;
        assert thisPath.size() == other.size();

        // Walk up and compare; it is more likely that the lower path segments differ (plus it's usually more efficient) ...
        while (!thisPath.isRoot() && thisPath.getLastSegment().equals(thatPath.getLastSegment())) {
            thisPath = thisPath.getParent();
            thatPath = thatPath.getParent();
        }
        return thisPath.isRoot();
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.value.Path

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.