/** * Get the {@link Path.Segment path segment} for this node. * * @return the path segment; never null */ public final Path.Segment getSegment() { return location.getPath().getLastSegment(); }
protected List<Segment> getSegments( List<Location> locations ) { List<Segment> segments = new ArrayList<Segment>(locations.size()); for (Location location : locations) { segments.add(location.getPath().getLastSegment()); } return segments; }
/** * Get the name of this node, without any same-name-sibling index. * * @return the name; never null */ public Name getName() { return location.getPath().getLastSegment().getName(); }
/** * {@inheritDoc} * * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Path) { Path that = (Path)obj; return that.isIdentifier() && idSegment.equals(that.getLastSegment()); } return false; }
@Override public boolean matchesSafely( List<Location> children ) { List<Path.Segment> childSegments = new ArrayList<Path.Segment>(children.size()); for (Location child : children) { childSegments.add(child.getPath().getLastSegment()); } return childMatcher.matches(childSegments); }
/** * {@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.isIdentifier() && idSegment.equals(other.getLastSegment()); }
/** * {@inheritDoc} * * @see java.lang.Comparable#compareTo(java.lang.Object) */ @Override public int compareTo( Path other ) { return other.isIdentifier() ? idSegment.compareTo(other.getLastSegment()) : super.compareTo(other); }
protected String getPrefixFor( Path path ) { Path.Segment lastSegment = path.getLastSegment(); String localName = lastSegment.getName().getLocalName(); int index = lastSegment.getIndex(); return getPrefixFor(localName, index); }
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()); }
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(); } };
public void create( Path path, Iterable<Property> properties ) { assert path != null; Path parent = path.getParent(); Name child = path.getLastSegment().getName(); requests.add(new CreateNodeRequest(Location.create(parent), workspace, child, properties)); }
public PathNode createNode( ExecutionContext context, String pathToNewNode, Map<Name, Property> properties, NodeConflictBehavior conflictBehavior ) { PathFactory pathFactory = context.getValueFactories().getPathFactory(); Path newPath = pathFactory.create(pathToNewNode); return createNode(context, getNode(newPath.getParent()), newPath.getLastSegment().getName(), properties, conflictBehavior); }
@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")); }
@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")); }
@Test public void shouldReturnNullForLastSegmentOfRoot() { if (path.isRoot()) { assertThat(path.getLastSegment(), is(nullValue())); } }
@Test public void shouldNeverReturnNullForLastSegmentOfNonRoot() { if (!path.isRoot()) { assertThat(path.getLastSegment(), is(notNullValue())); } }
public PathNode moveNode( ExecutionContext context, PathNode node, Name desiredNewName, WritablePathWorkspace originalWorkspace, PathNode newParent, PathNode beforeNode ) { if (desiredNewName == null) { assert !node.getPath().isRoot(); desiredNewName = node.getPath().getLastSegment().getName(); } PathNode newCopy = copyNode(context, node, originalWorkspace, newParent, desiredNewName, true); originalWorkspace.removeNode(context, node.getPath()); return newCopy; }
protected void createSubgraph( Batch batch, SubgraphNode initialNode, Path pathOfInitialNode ) { // Create the node with the properties ... batch.create(pathOfInitialNode).and(initialNode.getProperties()).ifAbsent().and(); // And create the children ... for (Location childLocation : initialNode.getChildren()) { Path path = childLocation.getPath(); SubgraphNode initialChild = initialNode.getNode(path.getLastSegment()); createSubgraph(batch, initialChild, path); } }