/** * {@inheritDoc} */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Path.Segment) { Path.Segment that = (Path.Segment)obj; if (!this.getName().equals(that.getName())) return false; return Math.abs(getIndex()) == Math.abs(that.getIndex()); } return false; }
/** * {@inheritDoc} */ @Override public boolean equals( Object obj ) { if (obj == this) return true; if (obj instanceof Path.Segment) { Path.Segment that = (Path.Segment)obj; if (!this.getName().equals(that.getName())) return false; return Math.abs(getIndex()) == Math.abs(that.getIndex()); } return false; }
if (sns != firstSegment.getIndex()) {
int snsIndex = 1; for (Node<Payload, PropertyPayload> sns : childrenWithName) { if (sns.getSegment().getIndex() != snsIndex) {
Segment existingSegment = existingSibling.getName(); if (existingSegment.getName().equals(name)) { int existingIndex = existingSegment.getIndex(); if (snsIndex == 0) snsIndex = existingIndex; existingSibling = (NodeType)existingSibling.withName(pathFactory.createSegment(name, existingIndex + 1));
MapNode prev = iter.previous(); if (prev.getName().getName().equals(name)) { nextIndex = prev.getName().getIndex() + 1; break;
assert index != -1; Name name = node.getName().getName(); int snsIndex = node.getName().getIndex(); WorkspaceChanges changes = getChangesFor(workspace, true); NodeType oldParent = (NodeType)parent.clone();
assert index != -1; Name name = node.getName().getName(); int snsIndex = node.getName().getIndex();
for (MapNode childWithSameName : childrenWithSameNames) { Path.Segment segment = childWithSameName.getName(); if (segment.getIndex() != index) { Path.Segment newName = context.getValueFactories().getPathFactory().createSegment(name, index); childWithSameName.setName(newName);
@Test public void shouldReorderChildWithSnsIndexes() { Node<Object, Object> sports = cache.findNodeWith(path("/Cars/Sports")); Node<Object, Object> cars = cache.findNodeWith(path("/Cars")); assertConnectionsUsed(1); // "Utility" was found because it is child of "Cars" loaded when "Sports" was loaded Node<Object, Object> exp1 = cars.createChild(name("Experimental")); Node<Object, Object> exp2 = cars.createChild(name("Experimental")); Node<Object, Object> exp3 = cars.createChild(name("Experimental")); assertThat(cache.hasPendingChanges(), is(true)); assertThat(exp1.getSegment().getIndex(), is(1)); assertThat(exp2.getSegment().getIndex(), is(2)); assertThat(exp3.getSegment().getIndex(), is(3)); assertChildren(cars, "Hybrid", "Sports", "Luxury", "Utility", "Experimental", "Experimental[2]", "Experimental[3]"); cars.orderChildBefore(exp3.getSegment(), sports.getSegment()); assertNoMoreConnectionsUsed(); assertThat(exp1.getSegment().getIndex(), is(2)); assertThat(exp2.getSegment().getIndex(), is(3)); assertThat(exp3.getSegment().getIndex(), is(1)); assertChildren(cars, "Hybrid", "Experimental", "Sports", "Luxury", "Utility", "Experimental[2]", "Experimental[3]"); // Save the changes ... assertConnectionsUsed(0); cache.save(); assertConnectionsUsed(2); // 1 to load children required by validation, 1 to perform save // Now the state should reflect our changes ... cars = cache.findNodeWith(path("/Cars")); assertChildren(cars, "Hybrid", "Experimental", "Sports", "Luxury", "Utility", "Experimental[2]", "Experimental[3]"); // Now there should be no changes ... assertNoChanges(); }
@Test public void shouldCreateParentReferenceSegmentIfPassedParentReferenceStringRegardlessOfIndex() { segment = factory.createSegment(Path.PARENT); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(true)); assertThat(segment.getName().getLocalName(), is(Path.PARENT)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); segment = factory.createSegment(Path.PARENT, 1); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(true)); assertThat(segment.getName().getLocalName(), is(Path.PARENT)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); }
@Test public void shouldCreateSelfReferenceSegmentIfPassedSelfReferenceStringRegardlessOfIndex() { segment = factory.createSegment(Path.SELF); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(true)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName().getLocalName(), is(Path.SELF)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); segment = factory.createSegment(Path.SELF, 1); assertThat(segment.getIndex(), is(Path.DEFAULT_INDEX)); assertThat(segment.hasIndex(), is(false)); assertThat(segment.isSelfReference(), is(true)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName().getLocalName(), is(Path.SELF)); assertThat(segment.getName().getNamespaceUri().length(), is(0)); }
@Test public void shouldHaveIndexSpecifiedInConstructor() { segment = new BasicPathSegment(validName, 3); assertThat(segment.getIndex(), is(3)); assertThat(segment.hasIndex(), is(true)); assertThat(segment.isSelfReference(), is(false)); assertThat(segment.isParentReference(), is(false)); assertThat(segment.getName(), is(validName)); }
/** * 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()); }
/** * {@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(); }
/** * {@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 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)); }
/** * 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()); }
@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)); }
protected String getPrefixFor( Path path ) { Path.Segment lastSegment = path.getLastSegment(); String localName = lastSegment.getName().getLocalName(); int index = lastSegment.getIndex(); return getPrefixFor(localName, index); }