Class JSONPaths
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.json_edit.JSONPaths
-
public class JSONPaths extends Object
Created by Jeff Gaynor
on 8/17/20 at 11:30 AM
-
-
Field Summary
Fields Modifier and Type Field Description static StringPARENT_COMPONENTstatic StringPATH_SEPARATORstatic StringSCHEME_DELIMITERstatic StringTHIS_COMPONENT
-
Constructor Summary
Constructors Constructor Description JSONPaths()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 String[]getComponents(String path)static StringgetFileName(String path)static StringgetParentPath(String 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 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 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
-
isAbsolute
public 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:
-
getUnqPath
public static String getUnqPath(String fqPath)
Takes a fully qualified path and returns the path without the scheme- Parameters:
fqPath-- Returns:
-
toPathComponents
public 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:
-
getComponentAt
public 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:
-
subpath
public 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:
-
startsWith
public 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:
-
endsWith
public 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:
-
normalize
public static String normalize(String path)
Removes redundant path components.- Parameters:
path-- Returns:
-
resolve
public 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 si actually absolute, this will return that. If the relative Path is trivial, the 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:
-
resolveSibling
public 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:
-
relativize
public 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:
-
compareTo
public 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- rinother-- Returns:
-
equals
public 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:
-
main
public static void main(String[] args)
-
isUnq
public static boolean isUnq(String path)
Is this path unqualified? I.e., there is no scheme- Parameters:
path-- Returns:
-
-