private boolean invariants() { assert null != getUri(); assert !getUri().isAbsolute(); assert null == getUri().getRawAuthority(); assert null != getUri().getRawPath(); assert null == getUri().getRawFragment(); assert getUri().normalize() == getUri(); String p = getUri().getRawPath(); assert !"..".equals(p); assert !p.startsWith(SEPARATOR); assert !p.startsWith("." + SEPARATOR); assert !p.startsWith(".." + SEPARATOR); assert !p.endsWith(SEPARATOR); return true; }
/** * Returns {@code true} if and only if the path component of this file * system node name is empty and no query component is defined. * * @return {@code true} if and only if the path component of this file * system node name is empty and no query component is defined. */ public boolean isRoot() { //return getUri().toString().isEmpty(); final URI uri = getUri(); final String path = uri.getRawPath(); if (null != path && !path.isEmpty()) return false; final String query = uri.getRawQuery(); return null == query; }
if (uri.isOpaque()) { final URI mpu = mountPoint.toHierarchicalUri(); final URI enu = nodeName.getUri(); try { return this.hierarchical = enu.toString().isEmpty()
private boolean invariants() { assert null != getUri(); assert getUri().isAbsolute(); assert null == getUri().getRawQuery(); assert null == getUri().getRawFragment(); if (getUri().isOpaque()) { assert getUri().getRawSchemeSpecificPart().endsWith(SEPARATOR); final FsNodePath path = getPath(); assert null != path; assert path.getUri().isAbsolute(); assert null == path.getUri().getRawFragment(); assert 0 != path.getNodeName().getUri().getRawPath().length(); } else { assert getUri().normalize() == getUri(); assert getUri().getRawPath().endsWith(FsNodeName.SEPARATOR); assert null == getPath(); } return true; }
/** * Returns the nullable parent of the given file system node path. * * @param path a file system node path. * @return The parent file system node path or null if {@code path} does * not name a parent. * @throws URISyntaxException */ static @Nullable FsNodePath parent(FsNodePath path) throws URISyntaxException { FsMountPoint mp = path.getMountPoint(); FsNodeName en = path.getNodeName(); if (en.isRoot()) { if (null == mp) return null; path = mp.getPath(); if (null != path) return parent(path); URI mpu = mp.getUri(); URI pu = mpu.resolve(DOT_DOT_URI); if (mpu.getRawPath().length() <= pu.getRawPath().length()) return null; return new FsNodePath(pu); } else { URI pu = en.getUri().resolve(DOT_URI); en = new FsNodeName(pu, CANONICALIZE); return new FsNodePath(mp, en); } } }
private boolean invariants() { assert null != getUri(); assert null == getUri().getRawFragment(); assert (null != getMountPoint()) == getUri().isAbsolute(); assert null != getNodeName(); if (getUri().isOpaque()) { assert getUri().getRawSchemeSpecificPart().contains(FsMountPoint.SEPARATOR); /*try { assert getUri().equals(new URI(getMountPoint().getUri().getScheme(), getMountPoint().getUri().getSchemeSpecificPart() + toDecodedUri(getNodeName()), null)); } catch (URISyntaxException ex) { throw new AssertionError(ex); }*/ } else if (getUri().isAbsolute()) { assert getUri().normalize() == getUri(); assert getUri().equals(getMountPoint().getUri().resolve(getNodeName().getUri())); } else { assert getUri().normalize() == getUri(); assert getNodeName().getUri() == getUri(); } return true; }
/** * Constructs a new opaque mount point by composing its URI from the given * scheme and path. * * @param scheme the non-{@code null} {@link #getScheme() scheme}. * @param path the non-{@code null} {@link #getPath() path}. * @throws URISyntaxException if the composed mount point URI would not * conform to the syntax constraints for mount points. */ public FsMountPoint(final FsScheme scheme, final FsNodePath path) throws URISyntaxException { final URI pu = path.getUri(); if (!pu.isAbsolute()) throw new QuotedUriSyntaxException(pu, "Path not absolute"); final String penup = path.getNodeName().getUri().getPath(); if (0 == penup.length()) throw new QuotedUriSyntaxException(pu, "Empty node name"); this.uri = new UriBuilder(true) .scheme(scheme.toString()) .path(pu.getScheme() + ':' + pu.getRawSchemeSpecificPart() + SEPARATOR) .toUri(); this.scheme = scheme; this.path = path; assert invariants(); }