public Set<Name> getUniqueChildNames() { if (this.uniqueChildNames == null) { Set<Name> childNames = new HashSet<Name>(childSegments.size()); for (Segment childSegment : childSegments) { childNames.add(childSegment.getName()); } this.uniqueChildNames = childNames; } return null; }
/** * {@inheritDoc} */ public Name create( Path.Segment segment ) { if (segment == null) return null; // Can only convert if the path has no SNS index ... if (!segment.hasIndex()) return segment.getName(); throw new ValueFormatException(segment, getPropertyType(), GraphI18n.errorConvertingType.text(Path.Segment.class.getSimpleName(), Name.class.getSimpleName(), segment)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#endsWith(org.modeshape.graph.property.Name, int) */ public boolean endsWith( Name nameOfLastSegment, int snsIndex ) { Segment segment = getLastSegment(); return segment != null && segment.getName().equals(nameOfLastSegment) && segment.getIndex() == snsIndex; }
@Test public void shouldConsiderEqualTwoSegmentsWithSameNameAndIndex() { segment = new BasicPathSegment(validName); segment2 = new BasicPathSegment(validName); assertThat(segment.equals(segment2), is(true)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName(), is(validName)); }
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 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()); } };
/** * Get the child with the supplied segment. * * @param segment the segment of the child * @return the child with the supplied name and SNS index, or null if the children have not yet been loaded * @throws PathNotFoundException if the children have been loaded and the child does not exist * @throws RepositorySourceException if there is a problem loading this node's information from the store */ public Node<Payload, PropertyPayload> getChild( Path.Segment segment ) { return getChild(segment.getName(), segment.getIndex()); }
protected String getPrefixFor( Path path ) { Path.Segment lastSegment = path.getLastSegment(); String localName = lastSegment.getName().getLocalName(); int index = lastSegment.getIndex(); return getPrefixFor(localName, index); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.Path#endsWith(org.modeshape.graph.property.Name) */ public boolean endsWith( Name nameOfLastSegment ) { Segment segment = getLastSegment(); return segment != null && segment.getName().equals(nameOfLastSegment) && !segment.hasIndex(); }
/** * 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} */ public int compareTo( Path.Segment that ) { if (this == that) return 0; int diff = this.getName().compareTo(that.getName()); if (diff != 0) return diff; return this.getIndex() - that.getIndex(); }
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 shouldParsePathFromStringWithoutRootSegmentAndIdentifierSegment() { path = paths.create("[f81d4fae-7dec-11d0-a765-00a0c91e6bf6]"); assertThat(path.isAbsolute(), is(true)); assertThat(path.isIdentifier(), is(true)); assertThat(path.size(), is(1)); assertThat(path.getSegment(0), is(segment("[f81d4fae-7dec-11d0-a765-00a0c91e6bf6]"))); assertThat(path.getSegment(0).getName(), is(name("f81d4fae-7dec-11d0-a765-00a0c91e6bf6"))); assertThat(path.getSegment(0).getIndex(), is(1)); assertThat(path.getSegment(0).isIdentifier(), is(true)); }
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()); }
@Test public void shouldNotHaveIndexByDefault() { segment = new BasicPathSegment(validName); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName(), is(validName)); }
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)); }
@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")); }
/** * Determine whether this node has a child with the supplied name and SNS index. * * @param segment the segment of the child * @return true if there is a child, or false if there is no such child * @throws RepositorySourceException if there is a problem loading this node's information from the store */ public boolean hasChild( Path.Segment segment ) { return hasChild(segment.getName(), segment.getIndex()); }