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(path1.equals(path2), is(true));
    }

    @Test
    public void shouldConsiderTwoDifferentPathsNotEqual() {
        Path path1 = pathFactory.create("/a/b/c");
        Path path2 = pathFactory.create("/a/b/d");
        assertThat(path1.equals(path2), is(false));

        path2 = pathFactory.create("/a/b");
        assertThat(path1.equals(path2), is(false));
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

        path.getCommonAncestor(null);
    }

    @Test
    public void shouldFindLowestCommonAncestorBetweenTwoNonRootNodesOnCommonBranch() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path common = pathFactory.create("/a");
        assertThat(path1.getCommonAncestor(path2), is(common));

        path1 = pathFactory.create("/a/b/c");
        path2 = pathFactory.create("/a/b/c/d");
        common = path1;
View Full Code Here

        assertThat(path1.getCommonAncestor(path2), is(common));
    }

    @Test
    public void shouldConsiderRootTheLowestCommonAncestorOfAnyNodesOnSeparateBrances() {
        Path path1 = pathFactory.create("/x/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path common = ROOT;
        assertThat(path1.getCommonAncestor(path2), is(common));
    }
View Full Code Here

        assertThat(path1.getCommonAncestor(path2), is(common));
    }

    @Test
    public void shouldConsiderNodeToBeAncestorOfEveryDecendantNode() {
        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");
        Path common = pathFactory.create("/a");
        assertThat(common.isAncestorOf(path1), is(true));
        assertThat(common.isAncestorOf(path2), is(true));
        assertThat(common.isAncestorOf(path3), is(false));

        assertThat(path1.getParent().isAncestorOf(path1), is(true));
        for (int i = 1; i < path1.size(); ++i) {
            assertThat(path1.getAncestor(i).isAncestorOf(path1), is(true));
        }
View Full Code Here

        }
    }

    @Test
    public void shouldConsiderNodeToBeDecendantOfEveryAncestorNode() {
        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");
        Path common = pathFactory.create("/a");
        assertThat(path1.isDescendantOf(common), is(true));
        assertThat(path2.isDescendantOf(common), is(true));
        assertThat(path3.isDescendantOf(common), is(false));

        assertThat(path1.getParent().isAncestorOf(path1), is(true));
View Full Code Here

        }
    }

    @Test
    public void shouldNotConsiderNodeToBeAncestorOfItself() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        assertThat(path1.isAncestorOf(path1), is(false));
        assertThat(path2.isAncestorOf(path2), is(false));
        assertThat(path3.isAncestorOf(path3), is(false));
        assertThat(ROOT.isAncestorOf(ROOT), is(false));
    }
View Full Code Here

        assertThat(ROOT.isAncestorOf(ROOT), is(false));
    }

    @Test
    public void shouldNotConsiderNodeToBeDecendantOfItself() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        assertThat(path1.isDescendantOf(path1), is(false));
        assertThat(path2.isDescendantOf(path2), is(false));
        assertThat(path3.isDescendantOf(path3), is(false));
        assertThat(ROOT.isDescendantOf(ROOT), is(false));
    }
View Full Code Here

        assertThat(ROOT.isDescendantOf(ROOT), is(false));
    }

    @Test
    public void shouldNotConsiderRootToBeDecendantOfAnyNode() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path common = pathFactory.create("/a");
        assertThat(ROOT.isDescendantOf(path1), is(false));
        assertThat(ROOT.isDescendantOf(path2), is(false));
        assertThat(ROOT.isDescendantOf(path3), is(false));
        assertThat(ROOT.isDescendantOf(common), is(false));
    }
View Full Code Here

        assertThat(ROOT.isDescendantOf(common), is(false));
    }

    @Test
    public void shouldConsiderRootToBeAncestorOfAnyNode() {
        Path path1 = pathFactory.create("/a/y/z");
        Path path2 = pathFactory.create("/a/b/c");
        Path path3 = pathFactory.create("/x/b/c");
        Path common = pathFactory.create("/a");
        assertThat(ROOT.isAncestorOf(path1), is(true));
        assertThat(ROOT.isAncestorOf(path2), is(true));
        assertThat(ROOT.isAncestorOf(path3), is(true));
        assertThat(ROOT.isAncestorOf(common), is(true));
    }
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.