Class JSONPaths


  • public class JSONPaths
    extends Object

    Created by Jeff Gaynor
    on 8/17/20 at 11:30 AM

    • Field Detail

      • SCHEME_DELIMITER

        public static String SCHEME_DELIMITER
      • PATH_SEPARATOR

        public static String PATH_SEPARATOR
      • THIS_COMPONENT

        public static String THIS_COMPONENT
      • PARENT_COMPONENT

        public static String PARENT_COMPONENT
    • Constructor Detail

      • JSONPaths

        public JSONPaths()
    • 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:
      • getFileName

        public static String getFileName​(String path)
      • getParentPath

        public static String getParentPath​(String path)
      • 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. So A#a/b/c and 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 - rin
        other -
        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)
      • getComponents

        public static String[] getComponents​(String path)
      • isUnq

        public static boolean isUnq​(String path)
        Is this path unqualified? I.e., there is no scheme
        Parameters:
        path -
        Returns:
      • getScheme

        public static String getScheme​(String path)
        Returns the scheme for this path or an empty string if there is none.
        Parameters:
        path -
        Returns: