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(resolved.isAbsolute(), is(true));
    }

    @Test( expected = InvalidPathException.class )
    public void shouldNotResolveRelativePathUsingAnAbsolutePath() {
        Path other = mock(Path.class);
        when(other.isAbsolute()).thenReturn(true);
        root.resolve(other);
    }
View Full Code Here


        root.resolve(other);
    }

    @Test
    public void shouldAlwaysConsiderRootAsLessThanAnyPathOtherThanRoot() {
        Path other = mock(Path.class);
        when(other.isRoot()).thenReturn(false);
        assertThat(root.compareTo(other), is(-1));
        assertThat(root.equals(other), is(false));
    }
View Full Code Here

        assertThat(root.equals(other), is(false));
    }

    @Test
    public void shouldAlwaysConsiderRootAsEqualToAnyOtherRoot() {
        Path other = mock(Path.class);
        when(other.isRoot()).thenReturn(true);
        assertThat(root.compareTo(other), is(0));
        assertThat(root.equals(other), is(true));
        assertThat(root.equals(root), is(true));
    }
View Full Code Here

        CachedNode node = versionStorageNode();
        MutableCachedNode mutable = null;

        // Find the parent of the version history node by walking the path and creating any missing intermediate folders ...
        Path parentPathInStorage = versionHistoryPath.getParent().subpath(2);
        Property primaryType = null;
        for (Segment segment : parentPathInStorage) {
            ChildReferences childRefs = node.getChildReferences(system);
            ChildReference ref = childRefs.getChild(segment);
            if (ref != null) {
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

    @Override
    @Test
    public void shouldNotConsiderNodeToBeAncestorOfItself() {
        super.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

    @Override
    @Test
    public void shouldNotConsiderNodeToBeDecendantOfItself() {
        super.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

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.