/** * {@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; }
/** * {@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 static UUID identifierFor( Path identifierPath ) { if (!identifierPath.isIdentifier()) return null; // Get the identifier segment ... Segment segment = identifierPath.getLastSegment(); assert segment.isIdentifier(); String id = segment.getName().getLocalName(); try { // The local part of the segment's name should be the identifier, though it may not be a UUID ... return UUID.fromString(id); } catch (IllegalArgumentException err) { String pathStr = "[" + id + "]"; throw new IllegalArgumentException(GraphI18n.identifierPathContainedUnsupportedIdentifierFormat.text(pathStr)); } }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.PathFactory#create(org.modeshape.graph.property.Path, java.lang.Iterable) */ public Path create( Path parentPath, Iterable<Segment> segments ) { CheckArg.isNotNull(parentPath, "parent path"); if (parentPath.isIdentifier()) { throw new InvalidPathException(GraphI18n.unableToCreatePathBasedUponIdentifierPath.text(parentPath, segments.toString())); } List<Segment> segmentsList = new LinkedList<Segment>(); segmentsList.addAll(parentPath.getSegmentsList()); for (Segment segment : segments) { if (segment == null) { CheckArg.containsNoNulls(segments, "segments"); } assert segment != null; if (segment.isIdentifier()) { throw new InvalidPathException( GraphI18n.unableToCreatePathUsingIdentifierPathAndAnotherPath.text(parentPath, segments.toString())); } segmentsList.add(segment); } if (segmentsList.isEmpty()) return RootPath.INSTANCE; if (segmentsList.size() == 0) return new ChildPath(parentPath, segmentsList.get(0)); return new BasicPath(segmentsList, parentPath.isAbsolute()); }
CheckArg.isNotNull(parentPath, "parentPath"); CheckArg.isNotNull(subpath, "subpath"); if (parentPath.isIdentifier()) { throw new InvalidPathException(GraphI18n.unableToCreatePathBasedUponIdentifierPath.text(parentPath, subpath));
if (segments == null || segments.length == 0) return RootPath.INSTANCE; if (segments.length == 1 && segments[0] != null) { if (parentPath.isIdentifier()) { throw new InvalidPathException(GraphI18n.unableToCreatePathBasedUponIdentifierPath.text(parentPath, segments.toString()));
/** * {@inheritDoc} */ public UUID create( Path value ) { if (value.isIdentifier()) { // Get the identifier segment ... Segment segment = value.getLastSegment(); assert segment.isIdentifier(); try { // The local part of the segment's name should be the identifier, though it may not be a UUID ... String id = segment.getName().getLocalName(); return UUID.fromString(id); } catch (IllegalArgumentException err) { throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value)); } } throw new ValueFormatException(value, PropertyType.UUID, GraphI18n.unableToCreateValue.text(getPropertyType().getName(), Path.class.getSimpleName(), value)); }
/** * Find the node with the supplied path. This node quickly finds the node if it exists in the cache, or if it is not in the * cache, it loads the nodes down the supplied path. * * @param path the path to the node * @return the node information * @throws PathNotFoundException if the node at the supplied path does not exist * @throws AccessControlException if the user does not have permission to read the nodes given by the supplied path */ public Node<Payload, PropertyPayload> findNodeWith( Path path ) throws PathNotFoundException, AccessControlException { if (path.isRoot()) return getRoot(); if (path.isIdentifier()) return findNodeWith(Location.create(path)); return findNodeRelativeTo(root, path.relativeTo(root.getPath()), true); }
/** * Find the node with the supplied path. This node quickly finds the node if it exists in the cache, or if it is not in the * cache, it loads the nodes down the supplied path. However, if <code>loadIfRequired</code> is <code>false</code>, then any * node along the path that is not loaded will result in this method returning null. * * @param path the path to the node * @param loadIfRequired true if any missing nodes should be loaded, or false if null should be returned if any nodes along * the path are not loaded * @return the node information * @throws PathNotFoundException if the node at the supplied path does not exist * @throws AccessControlException if the user does not have permission to read the nodes given by the supplied path */ protected Node<Payload, PropertyPayload> findNodeWith( Path path, boolean loadIfRequired ) throws PathNotFoundException, AccessControlException { if (path.isRoot()) return getRoot(); if (path.isIdentifier()) return findNodeWith(Location.create(path)); return findNodeRelativeTo(root, path.relativeTo(root.getPath()), loadIfRequired); }
@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)); }