Package org.qdl_lang.vfs
Class VFSPaths
- java.lang.Object
- 
- org.qdl_lang.vfs.VFSPaths
 
- 
 public class VFSPaths extends Object This is compatible with thePathinterface but does not implement it. The reason is that whileFileSystemis really slick, policies for accessing files are set by the security manager per JVM. So, if this code is to run on a server with restricted access to the real file system (but access its own virtual mounts) we have to restrict access for the entire JVM which means that the server can no longer function, at least without very specific configuration which is going to be hard for others to do. As such until something changes, we can't actually use the Java stuff, which, to be fair, is made so that Java developers have seamless access to various file systems.
 A path in the store is of the formscheme#/a/b/c/d (absolute) scheme#p/q/r (relative)as such these are almost uris. The problem with using a URI vs this is that we must have a scheme at all times to tell us which store this goes in and relative uris do not have schemes. No scheme (which probably should include#/a/b/c) means native file.Created by Jeff Gaynor 
 on 2/29/20 at 7:03 AM
- 
- 
Field SummaryFields Modifier and Type Field Description static StringPARENT_COMPONENTstatic StringPATH_SEPARATORstatic StringSCHEME_DELIMITERstatic StringTHIS_COMPONENT
 - 
Constructor SummaryConstructors Constructor Description VFSPaths()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancheckScheme(String scheme, String path)Check is a path has this scheme.static intcompareTo(String path, String other)Lexically compares two paths without schemes.static booleanendsWith(String path, String other)Does this path end with the other? E.g.static booleanequals(String path1, String path2)Compares two paths.static StringgetComponentAt(String path, int index)Returns the path component at the given index.static StringgetFileName(String path)static StringgetParentPath(String path)intgetPathComponentCount(String path)The number of components in this path.static StringgetScheme(String path)Returns the scheme for this path or an empty string if there is none.static StringgetUnqPath(String fqPath)Takes a fully qualified path and returns the path without the schemestatic booleanhasSameScheme(String path1, String path2)Check if two paths have the same schemestatic booleanisAbsolute(String path)Returns if this path is absolute, i.e.static booleanisUnq(String path)Is this path unqualified? I.e., there is no schemestatic booleanisVFSPath(String path)static voidmain(String[] args)static Stringnormalize(String path)Removes redundant path components.static Stringrelativize(String path, String other)Attempts to relativize the other path against the path.static Stringresolve(String path, String relativePath)Resolves the relativePath against the path.static StringresolveSibling(String path, String other)This resolves the other against the parent of the path -- making them siblings, i.e.static booleanstartsWith(String path, String other)Does the path start with the other path? So if path=A#/a/b/c/d and other=B#/a/b the answer is true.static Stringsubpath(String path, int beginIndex, int endIndex)Returns a subpath of components.static String[]toPathComponents(String path)Return the un-normalized components of this path.
 
- 
- 
- 
Method Detail- 
isVFSPathpublic static boolean isVFSPath(String path) 
 - 
checkSchemepublic static boolean checkScheme(String scheme, String path) Check is a path has this scheme. True if so, false if not- Parameters:
- scheme-
- path-
- Returns:
 
 - 
hasSameSchemepublic static boolean hasSameScheme(String path1, String path2) Check if two paths have the same scheme- Parameters:
- path1-
- path2-
- Returns:
 
 - 
isUnqpublic static boolean isUnq(String path) Is this path unqualified? I.e., there is no scheme- Parameters:
- path-
- Returns:
 
 - 
getSchemepublic static String getScheme(String path) Returns the scheme for this path or an empty string if there is none.- Parameters:
- path-
- Returns:
 
 - 
isAbsolutepublic static boolean isAbsolute(String path) Returns if this path is absolute, i.e. if it starts with the path separator. So A#/a/b/c is absolute, A#b/c is not.
 An absolute path contains enough information to find the file. A relative path does not. This will compare them ignoring schemes.- Parameters:
- path-
- Returns:
 
 - 
getUnqPathpublic static String getUnqPath(String fqPath) Takes a fully qualified path and returns the path without the scheme- Parameters:
- fqPath-
- Returns:
 
 - 
getPathComponentCountpublic int getPathComponentCount(String path) The number of components in this path. Note that this does not, e.g.normalize(String)this path first so if that is an issue, normalize first.- Parameters:
- path-
- Returns:
 
 - 
toPathComponentspublic static String[] toPathComponents(String path) Return the un-normalized components of this path. So A#a/b/c would return the array{"a","b","c"}, as would the relative path a/b/c.- Parameters:
- path-
- Returns:
 
 - 
getComponentAtpublic static String getComponentAt(String path, int index) Returns the path component at the given index. SoA#a/b/cand index = 1 returns "b".- Parameters:
- path-
- index-
- Returns:
 
 - 
subpathpublic static String subpath(String path, int beginIndex, int endIndex) Returns a subpath of components. This is FQ if the argument was/- Parameters:
- beginIndex-
- endIndex-
- Returns:
 
 - 
startsWithpublic static boolean startsWith(String path, String other) Does the path start with the other path? So if path=A#/a/b/c/d and other=B#/a/b the answer is true. Note that the paths are compared here, not the schemes so you can use this when comparing paths in different stores.- Parameters:
- path-
- other-
- Returns:
 
 - 
endsWithpublic static boolean endsWith(String path, String other) Does this path end with the other? E.g. path=A#/a/b/c/d other=B#c/d would return true.- Parameters:
- path-
- other-
- Returns:
 
 - 
normalizepublic static String normalize(String path) Removes redundant path components.- Parameters:
- path-
- Returns:
 
 - 
resolvepublic static String resolve(String path, String relativePath) Resolves the relativePath against the path. So if path=A#/a/b/c and relativePath=B#q/r then this returns A#/a/b/c/q/r. Note two edge cases. If the relativePath is actually absolute, this will return that. If the relativePath is trivial, the path is returned. In point of fact
 relativize(p,resolve(p,q)).equals(q)
 as long as they have the same scheme (or the relative path gets the scheme of the path).- Parameters:
- path-
- relativePath-
- Returns:
 
 - 
resolveSiblingpublic static String resolveSibling(String path, String other) This resolves the other against the parent of the path -- making them siblings, i.e. in the same directory. So if path=A#/a/b/c/d and other=q the result is A#/a/b/c/q, i.e., d and q are now siblings in the directory A#/a/b/c.- Parameters:
- path-
- other-
- Returns:
 
 - 
relativizepublic static String relativize(String path, String other) Attempts to relativize the other path against the path. So if path=/a/b other=/a/b/c/d then this returns c/d. In point of fact
 relativize(p,resolve(p,q)).equals(q)
 as long as they have the same scheme (or the relative path gets the scheme of the path).- Parameters:
- path-
- other-
- Returns:
 
 - 
compareTopublic static int compareTo(String path, String other) Lexically compares two paths without schemes. This returns a 0 (zero) if they are equal. This may not make much sense if they are in different schemes, but it does allow to see when two paths are otherwise equal.- Parameters:
- path-
- other-
- Returns:
 
 - 
equalspublic static boolean equals(String path1, String path2) Compares two paths. These are equal if their schemes are equal and their normalizations are.- Parameters:
- path1-
- path2-
- Returns:
 
 
- 
 
-