/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#isSameAs(org.modeshape.graph.property.Path) */ @Override public boolean isSameAs( Path other ) { CheckArg.isNotNull(other, "other"); return other.isRoot(); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#isRoot() */ public boolean isRoot() { if (child.isParentReference()) return parent.isRoot(); return false; }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#isAtOrBelow(org.modeshape.graph.property.Path) */ @Override public boolean isAtOrBelow( Path other ) { CheckArg.isNotNull(other, "other"); return other.isRoot(); }
public int compare( Object parentLocation, Object childLocation ) { if (parentLocation == null) return parentLocation == null ? 0 : -1; else if (parentLocation == null) return 1; Path childPath = ((Location)childLocation).getPath(); Path parentPath = ((Location)parentLocation).getPath(); if (childPath.isRoot()) return parentPath.isRoot() ? 0 : -1; Path parentOfChild = childPath.getParent(); return pathComparator.compare(parentPath, parentOfChild); } };
public int compare( Object childLocation, Object parentLocation ) { if (childLocation == null) return parentLocation == null ? 0 : -1; else if (parentLocation == null) return 1; Path childPath = ((Location)childLocation).getPath(); Path parentPath = ((Location)parentLocation).getPath(); if (childPath.isRoot()) return parentPath.isRoot() ? 0 : -1; Path parentOfChild = childPath.getParent(); return pathComparator.compare(parentPath, parentOfChild); } };
@Test public void shouldReturnRootForLowestCommonAncestorWithAnyNodePath() { Path other = mock(Path.class); when(other.isRoot()).thenReturn(true); assertThat(root.getCommonAncestor(other).isRoot(), is(true)); when(other.isRoot()).thenReturn(false); assertThat(root.getCommonAncestor(other).isRoot(), is(true)); }
public boolean evaluate( Object parentLocation, Object childLocation ) { if (childLocation == null || parentLocation == null) return false; Path childPath = ((Location)childLocation).getPath(); Path parentPath = ((Location)parentLocation).getPath(); if (childPath.isRoot()) return false; return parentPath.isSameAs(childPath.getParent()); } };
public boolean evaluate( Object childLocation, Object parentLocation ) { if (childLocation == null || parentLocation == null) return false; Path childPath = ((Location)childLocation).getPath(); Path parentPath = ((Location)parentLocation).getPath(); if (childPath.isRoot()) return false; return parentPath.isSameAs(childPath.getParent()); } };
public T to( Path desiredPath ) { if (desiredPath.isRoot()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredPath)); } Path parent = desiredPath.getParent(); return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName()); }
@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)); }
@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)); }
public T to( Location desiredLocation ) { if (!desiredLocation.hasPath()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToLocationWithoutAPath.text(this.from, desiredLocation)); } Path desiredPath = desiredLocation.getPath(); if (desiredPath.isRoot()) { throw new IllegalArgumentException(GraphI18n.unableToCopyToTheRoot.text(this.from, desiredLocation)); } Path parent = desiredPath.getParent(); return submit(this.fromWorkspaceName, this.from, Location.create(parent), desiredPath.getLastSegment().getName()); }
public Object evaluate( Object[] tuple ) { Location location = (Location)tuple[locationIndex]; if (location == null) return null; Path path = location.getPath(); assert path != null; return path.isRoot() ? "" : stringFactory.create(location.getPath().getLastSegment().getName()); } };
public Object evaluate( Object[] tuple ) { Location location = (Location)tuple[locationIndex]; if (location == null) return null; Path path = location.getPath(); assert path != null; return path.isRoot() ? "" : location.getPath().getLastSegment().getName().getLocalName(); } };
@Test public void shouldConstructRootPathFromStringWithSingleDelimiter() { assertThat(pathFactory.create("/"), is(ROOT)); assertThat(pathFactory.create("/").isRoot(), is(true)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.request.processor.RequestProcessor#process(org.modeshape.graph.request.VerifyWorkspaceRequest) */ @Override public void process( VerifyWorkspaceRequest request ) { VerifyNodeExistsRequest source = (VerifyNodeExistsRequest)federatedRequest.getFirstProjectedRequest().getRequest(); if (checkErrorOrCancel(request, source)) return; assert source.getActualLocationOfNode().getPath().isRoot(); request.setActualRootLocation(source.getActualLocationOfNode()); }
@Test public void shouldPlaceContentUnderRootIfNoPathIsProvidedInConstructor() { parentPath = null; handler = new XmlHandler(destination, skipRootElement, parentPath, decoder, nameAttribute, typeAttribute, typeAttributeValue, scoping); assertThat(handler.destination, is(sameInstance(destination))); assertThat(handler.currentPath.isRoot(), is(true)); assertThat(handler.skipFirstElement, is(skipRootElement)); assertThat(handler.decoder, is(sameInstance(decoder != null ? decoder : XmlHandler.DEFAULT_DECODER))); assertThat(handler.nameAttribute, is(sameInstance(nameAttribute))); }
@Test( expected = IndexOutOfBoundsException.class ) public void shouldNotAllowSubpathStartingAtIndexEqualToSize() { if (path.isRoot()) path.subpath(1); path.subpath(path.size()); }
@Test public void shouldReadTheChildrenOfTheRootNode() { List<Location> children = graph.getChildren().of("/"); assertThat(children, is(notNullValue())); for (Location child : children) { // Check the location has a path that has the root as a parent ... assertThat(child.hasPath(), is(true)); assertThat(child.getPath().getParent().isRoot(), is(true)); // Verify that each node can be read multiple ways ... readNodeThoroughly(child); } }
@Override public MockPathNode removeNode( Path path ) { if (path.isRoot()) { InternalNode oldRoot = rootNode; removeAll(); return pathNodeFor(oldRoot); } InternalNode target = nodeAt(path); InternalNode parent = target.getParent(); parent.removeChild(target.getName()); return pathNodeFor(target); }